java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
Solution 1
You have to put the full path to the jarfile in the classpath (including the filename):
.;C:\j2sdk1.4.2_16\jre\lib;
C:\Program Files\mysql-connector-java-3.1.144\mysql-connector-java-3.1.14-bin.jar
As Hippo said, you have to restart cmd
after changing that. If it doesn't work, launch your program like this:
java -cp ".;C:\j2sdk1.4.2_16\jre\lib;
C:\Program Files\mysql-connector-java-3.1.144\mysql-connector-java-3.1.14-bin.jar"
my.class.Name
Solution 2
- Open Netbeans IDE
- Right-click your Project.
- Select Properties.
- On the left-hand side click Libraries.
- Under "Compile" tab - click Add Jar/Folder button.
- Select Downloaded "mysql-connector-java-5.1.25-bin.jar" file (Download Connector/J from dev.mysql.com)
- Click OK
- Run Again... Its work.
Thanks...
SLA
Updated on May 11, 2020Comments
-
SLA about 4 years
I am getting this error when compiling my java program
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
Then I knew that I should add the path of
mysql-connector-java-3.1.14-bin.jar
to the java classpath. I am using Windows XP, I edited the classpath in the controlpanel/system/enviromental variablesthe classpath was :
.;C:\j2sdk1.4.2_16\jre\lib;
so now it became :
.;C:\j2sdk1.4.2_16\jre\lib;C:\Program Files\mysql-connector-java-3.1.144
however, i still get the same error, moreover, when I type set classpath in the cmd ( just to check what is the current classpath ) i get :
CLASSPATH= .;C:\j2sdk1.4.2_16\jre\lib;
can anyone help me fix this ?