title: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver when executing JAR
body: <p>I am attempting to connect to my local MySQL server with the following code:</p>
  
  <pre><code>dbURL = "jdbc:mysql://localhost:3306:/" + dbname;
  try{
      Class.forName("com.mysql.jdbc.Driver");
      try{
          con = DriverManager.getConnection(dbURL, dbuser, dbpass);
      } catch (SQLException ex){
          System.out.println("ERROR: Could not connection to SQL DB");
          con = null;
      }
  } catch (ClassNotFoundException e){
      System.out.println("Error: ");
      e.printStackTrace();
  }
  </code></pre>
  
  <p>I then get </p>
  
  <blockquote>
    <p>java.lang.ClassNotFoundException: com.mysql.jdbc.Driver</p>
  </blockquote>
  
  <p>I understand that Java cannot find the proper driver for connecting the Java environment to the MySQL database. This is being compiled on a Windows 7 system and ported over to an Ubuntu 11.04 system.</p>
  
  <p>Is there a particular way I can run the Java program with a particular classpath such as:</p>
  
  <pre><code>java -cp /usr/share/java/mysql-connector-java.jar program.jar
  </code></pre>
  
  <p>That didn't work when I tried it.</p>