theSound
theSound

Reputation: 1

cant connect to jdbc driver mysql

While I am trying to connect to mysql database using java class I am getting this error. Please help I have set the CLASSPATH: C:\mysql-connector-java-5.0.8\mysql-connector-java-5.0.8.jar

    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 connect.main(connect.java:17)
Cannot connect to database server
Exception in thread "main" java.lang.NullPointerException
    at connect.main(connect.java:29)

Upvotes: 0

Views: 5069

Answers (3)

KV Prajapati
KV Prajapati

Reputation: 94625

Remove the CLASSPATH environment variable and test your code as suggested by @morja and @pap. In case you want to set environment variable CLASSPATH, then the value of CLASSPATH must be: (Please verify the location of .jar or for the sake of simplicity shorten the folder and .jar file e.g c:\driver\mysqldriver.jar)

.;C:\mysql-connector-java-5.0.8\mysql-connector-java-5.0.8.jar

Upvotes: 0

pap
pap

Reputation: 27614

If you are getting that error, your classpath is not correct. Either you are not including it properly to the java process (java -cp <classpath> YourClass) or the mysql connector jar is not located where you are pointing at.

Upvotes: 2

morja
morja

Reputation: 8550

Add the driver to the classpath:

java -cp .;C:\mysql-connector-java-5.0.8\mysql-connector-java-5.0.8.jar connect

Upvotes: 2

Related Questions