I want to connect to my mySQL db with a java program.Im getting a ClassNotFoundException . I copied the mysql-connector-java-5.1.18-bin.jar file to the java lib folder and set classpath in user variables to the java/lib folder. i used the following statements to establish the connection:
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/ammy","system","system");
Error:
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at JDBCEx.main(JDBCEx.java:11)
This is what i get when i try to extract the jar file:
C:\Program Files\Java\jdk1.6.0_16\lib\mysql-connector-java-5.1.18-bin;.
Access is denied
Go to the user variable classpath option, then edit it and add
java/lib/mysql-connector-java-5.1.18-bin.jar to the classpath to make your work done
or download the ConnectorJ driver from the link
and then add that to your classpath. I am using this and it works fine.