14

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 variables

the 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 ?

SLA
  • 363
  • 2
  • 4
  • 11
  • 1
    maybe you missed .jar extension while editing classpath. – Vishwanath Nov 20 '10 at 13:56
  • 3
    Did you restart cmd after making the change? – AbdullahC Nov 20 '10 at 13:57
  • 2
    As a side note, I wouldn't add the classpath to mysql-connector to the CLASSPATH variable. You should simply specify this dependency directly: java -cp "C:\program files\mysql-connector..." com.yourcompany.MainClass – ripper234 Nov 20 '10 at 14:03

3 Answers3

17

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
thejh
  • 44,854
  • 16
  • 96
  • 107
8
  1. Open Netbeans IDE
  2. Right-click your Project.
  3. Select Properties.
  4. On the left-hand side click Libraries.
  5. Under "Compile" tab - click Add Jar/Folder button.
  6. Select Downloaded "mysql-connector-java-5.1.25-bin.jar" file (Download Connector/J from dev.mysql.com)
  7. Click OK
  8. Run Again... Its work.

Thanks...

Jaykumar Patel
  • 26,836
  • 12
  • 74
  • 76
0

You just need to copy the mysql-connector-java-5.1.39-bin file in the Libraries of the project folder. Everything will work fine.

lgaud
  • 2,430
  • 20
  • 30
HN Singh
  • 98
  • 2
  • 13