I am trying to connect to a local MySQL server with the following 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(); }
Then i get
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
I understand that Java cannot find a suitable driver for connecting the Java environment to the MySQL database. This compiles on Windows 7 and migrates to Ubuntu 11.04.
Is there any specific way to run a Java program with a specific class, for example:
java -cp /usr/share/java/mysql-connector-java.jar program.jar
This did not work when I tried.
source share