java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
I'm having problems connecting to the driver I've downloaded. The driver is mysql-connector-java-5.0.4-bin.jar, downloaded from mysql.com.
I've unpacked the zip-file I downloaded, put the jar-file, and the other files that came with it, in a folder at C:\driver\.
The problem occur when I try to access the driver from my java-code.
I added the full path to the jar-file (C:\driver\mysql-connector-java-5.0.4-bin.jar) in the classpath on my computer according to all instructions I have found. And I've even added the driver in Netbeans.
When I added the driver in Netbeans (under Runtime) it works fine. I can establish contact with the database there and execute querys, but when I try to access the driver from my code, using: Class.forName("com.mysql.jdbc.Driver");
I get a ClassNotFoundException and I can't figure out why! I got the address to the driver (in the code above) from the documentation of the driver.
I really can not figure out what's wrong! I've tried to change the classpath in a lot of different ways, by renamning the folder etc. And after every time I've also restarted the computer, and it still doesn't work!
Please, help me figure out what I've done wrong...
[1275 byte] By [
Pifaa] at [2007-11-26 16:03:18]

# 2
Since you're using NetBeans, you should know that it ignores any system CLASSPATH environment variables. So do all other IDEs. So do all Java EE containers. So does javac.exe and java.exe. In short, the CLASSPATH environment variable is utterly worthless. Delete it.
Learn how to add a 3rd party JAR to the CLASSPATH according to NetBeans.
%
# 4
> > So does javac.exe and java.exe
>
> Huh?
javac and java both refer to the classpath, in the same way that any IDE will. Any java process needs to know where to find the classes to compile, run or reference.
javac -classpath .;my-first-jar.jar;my-second-jar.jar src/org/stuff/myPackage/ClassToCompile.java
java -classpath .;my-first-jar.jar;my-second-jar.jar org.stuff.myPackage.ClassToRun
# 5
> javac and java both refer to the classpath, in the
> same way that any IDE will. Any java process needs to
> know where to find the classes to compile, run or
> reference.
If you don't explicitly provide a -classpath flag, however, the CLASSPATH environment variable is used.
set CLASSPATH=.;my-first-jar.jar;my-second-jar.jar
javac src\org\stuff\myPackage\ClassToCompile.java
java org.stuff.myPackage.ClassToRun
I don't recommend it, but it does work. Hence my "huh?".
D.
# 7
As I have the same problem, running Linux) can you,duffymo, tell us how to learn about 3rd party drivers (or point where to read about it.
Message was edited by:
JanPihlgren
By an excident i found whow to incloud the CLASSPATH:
At the project name click for expand
At Libraries click for expand
Then right-click at the word "Libraries"
Choose "Add JAR/Folders"
You will get a new window
Search for the file "mysql-connector-version-bin.jar"
choose that and click "Open"
Thats it.
Message was edited by:
JanPihlgren