I am trying to write a program to connect to a MySQL database in eclipse, but I get the error \"java.sql.SQLException: No suitable driver found\".
The java
Load Driver class just before getting the connection.
Use this code:
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test_db", "user", "passw");
I had the same problem. I solved it by adding:
Class.forName("com.mysql.jdbc.Driver");
Alternatively you can also add the installed jar file to your eclipse project by selecting the project in eclipse, right click it and go down to properties, select the Java Build Path>>select the Libraries Tab>>Add external jar file and browse for the installed mysql-connector-java.jar file or any mysql java connector file int the /usr/share/java/ directory for most ubuntu users. Click okay and rebuild your project. Good luck
you can place the path like java -cp
pwd/mysql-connector-java-5.1.22-bin.jar:. <classname>
.
make sure that your in same directory where the mysql driver is .
Hope that helps .
I encountered the same problem as you, but I handled it as follows: I copied the jar, which is called mysql-connector-java-5.1.23-bin.jar, into the \Apache Software Foundation\Tomcat 6.0\lib, and restarted tomcat. Hope that helps
For all but the most trivial applications the CLASSPATH
environment variable is NOT used. Normally the libraries are include in the Class-Path
entry in the manifest of the jar, or in the -cp
option of the java commandline.
In this case you need to add the MySQL JDBC driver to the buildpath of your Eclipse project.