I'm trying to get the JDBC to work on my Windows 7. I added it to the CLASSPATH ("G:/workspace/mysql-connector-java-5.1.18-bin.jar"). Restarted, because I thought this might be the problem. But the Class.forName("com.mysql.jdbc.Driver").newInstance() still is not working. It throws the following exception:
Exception in thread "main" java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at JDBCTest.main(JDBCTest.java:18)
And this is the code in my class:
....
private static Connection connect=null;
private static Statement statement=null;
private PreparedStatement preparedstament=null;
private static ResultSet resultset=null;
public static void main(String args[]) throws Exception
{
Class.forName("com.mysql.jdbc.Driver").newInstance();
connect=DriverManager.getConnection("jdbc:mysql://localhost/feedback?user=root&password=root");
statement=connect.createStatement();
How am I supposed to solve this?
java -jar myprog.jar
), theCLASSPATH
environment variable will be ignored. In that case you need to set the classpath in the manifest file of the JAR. – JesperClass.forName("com.mysql.jdbc.Driver");
Btw it's just an info, it actually doesn't resolve your problem. – alain.janinm