Whenever I run the following code:
import com.mysql.jdbc.Driver;
public void insertIntoMysql() {
// Print out classloader information
ClassLoader cl = ClassLoader.getSystemClassLoader();
URL[] urls = ((URLClassLoader) cl).getURLs();
String urlStr = "";
for (int i=0; i < urls.length; i++) {
urlStr += urls[i].getFile() + "\n";
}
System.out.println("Classpath:\n" + urlStr);
// connect to mysql
Class.forName("com.mysql.jdbc.Driver");
String myUrl = "jdbc:mysql://localhost:3306/Compass";
Connection conn = DriverManager.getConnection(myUrl, "root", "newpoint");
...
}
I get a "ClassNotFoundException: com.mysql.jdbc.Driver" error on the Class.forName line. However, my classpath prints out as:
Classpath:
...
/C:/myProjectDir/
and I have the following jar "/C:/myProjectDir/mysql-connector-java-5.0.8-bin.jar" within my classpath.
I've restarted the program just in case the ClassLoader is loading everything when the program starts, but I keep getting that error.
Any thoughts?
c:/myProjectDiron the classpath, notc:/myProjectDir/mysql-connector-java-5.0.8-bin.jar. Are you sure you have the jar on the classpath, and not just the directory?