wood burning stoves 2.0*
The moose likes JDBC and the fly likes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark ""..could not load JDBC driver."" Watch ""..could not load JDBC driver."" New topic
Author

"..could not load JDBC driver."

Tom Bevan
Greenhorn

Joined: Jun 30, 2003
Posts: 10
Hello,
This is my first question, sorry if this is a bit obvious, but I am baffled. Find classpath stuff a little scary!
Have followed as many suggestions and tutorials as I can find but I still can't seem to connect to the mySQL database I have created using Connector/J.
Tried to follow the Cattle Drive JDBC tutorial 1, but same error message appears when I try to run the Test java file.
1. I have installed MySQL (C:\mysql), created a databse (bibliography), and created a little table (AUTHOR). I am able to see the table in the console: sql>select * from author
2. I have downloaded the latest version of Connector/J (mysql-connector-java-3.0.8-stable.zip), and unzipped the zip file into my C:\ directory.
3. I copied the mysql-connector-java-3.0.8-stable-bin.jar to the C:\j2sdk1.4.1_01\jre\lib\ext folder, and placed it in the jakarta tomcat 4.1.24\common\lib directory.
Should I alter my classpath as well?
My classpath currently looks like this:
%path%;C:\j2sdk1.4.1_01\bin;;C:\apache-ant-1.5.3-1\bin;C:\MYSQL\BIN;

4. I have succesfully compiled a Java program usingTextPad, (Test.java):

5. When I run this java file, I get this message:
"...could not load JDBC driver:java.lang.ClassNotFounfExcepption: mysql.jdbc.Driver"
What am I doing wrong?
Tom Bevan

[ edited to preserve formatting using the [code] and [/code] UBB tags -ds ]
[ July 02, 2003: Message edited by: Dirk Schreckmann ]
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
I copied the mysql-connector-java-3.0.8-stable-bin.jar to the C:\j2sdk1.4.1_01\jre\lib\ext folder
If I recall correctly, this will work, but it's a dirty way of doing things as this directory is supposed to be for official Java extensions only. (Again, if I recall correctly.)
You might do well to get used to understanding and adjusting the CLASSPATH environment variable instead.
Should I alter my classpath as well?
My classpath currently looks like this:
%path%;C:\j2sdk1.4.1_01\bin;;C:\apache-ant-1.5.3-1\bin;C:\MYSQL\BIN;
4. I have succesfully compiled a Java program usingTextPad, (Test.java):

If TextPad compiles the code successfully, then you probably don't have to adjust your CLASSPATH.
Note that Tomcat doesn't pay attention to your CLASSPATH setting. It uses resources available in the common/lib folder, in the lib and classes folders of the web application, and one or two other locations as well. So, as you've done, you do need the Connector/J JAR in the common/lib folder (or in a different folder that Tomcat will use).
Also, note that the CLASSPATH and the PATH are two entirely different environment variables. %path%;C:\j2sdk1.4.1_01\bin;;C:\apache-ant-1.5.3-1\bin;C:\MYSQL\BIN; might make sense for a PATH setting, but it probably doesn't make much sense for a CLASSPATH setting.
The PATH setting tells the OS where to find executables.
The CLASSPATH setting tells the Java compiler and Runtime Environment where to find class files.
5. When I run this java file, I get this message:
"...could not load JDBC driver:java.lang.ClassNotFounfExcepption: mysql.jdbc.Driver"

It seems odd that your source code says com.mysql.jdbc.Driver while the error message says mysql.jdbc.Driver . I've haven't noted such discrepancies before. Are you certain that the posted code is the same as the code you used and that the posted error message is the same as experienced?


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Ah! I just noticed that your example app isn't running on the Tomcat server. You confused me with all that talk of Tomcat (what's up with that?).
I wonder if you're running a JRE other than the one into which you copied the Connector/J JAR.
Don't copy things into the JRE/ext directory. Set your CLASSPATH instead. So, perhaps place the Connector/J JAR in the C:\java\Connector-J folder, then set the CLASSPATH to be .;C:\java\Connector-J\mysql-connector-java-3.0.8-stable-bin.jar and try to run the app.
Note that the compiler doesn't check for the location of classes used with the Class.forName(String) method. This check is performed at runtime. So, something nonsensical, such as the following, compiles, but won't run very well.
Now, did you wade through these messy responses and figure 'er out yet?
Tom Bevan
Greenhorn

Joined: Jun 30, 2003
Posts: 10
Hello,
Many thanks for looking at this for me, I will see if I can sort it out.
(I am using Tomcat though..honest!)
I'll let you know how I get on.
Thanks again,
Tom.
Tom Bevan
Greenhorn

Joined: Jun 30, 2003
Posts: 10
Hello,
Pleased to say my driver is now loading and my connection is up and running!
Erm..I was confusing my Path and Classpath. Ooops.

Thanks again for all your help.
Cheers,
Tom
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Pleased to say my driver is now loading and my connection is up and running!
Woo hoo!
Erm..I was confusing my Path and Classpath. Ooops.
That's better than confusing either one with human anatomy.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: "..could not load JDBC driver."
 
Similar Threads
eclipse can not connect to mysql!!!
problem with mysql connecton!
MySQL Beginner Has Problem With Loading JDBC Driver
Error: ClassNotFoundException: com.jdbc.mysql.jdbcDriver,"No suitable driver"
classpath and jdbc