Meaningless Drivel is fun!*
The moose likes JDBC and the fly likes JDBC and MySQL Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "JDBC and MySQL Problem" Watch "JDBC and MySQL Problem" New topic
Author

JDBC and MySQL Problem

Paul Hoffman
Greenhorn

Joined: Nov 04, 2005
Posts: 19
Hi Folks,

Hope someone can help me because I'm getting awfully frustrated.

I am getting the following error upon trying to connect my servlet to a MySQL database:

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

I have downloaded the MySQL/J Connector. I have updated my CLASSPATH so that it points to:

C:\Program Files\Java\jdk1.5.0_05\jre\lib\ext\mysql-connector-java-3.1.12\mysql-connector-java-3.1.12-bin.jar

My connection string looks like this:

Class.forName("com.mysql.jdbc.Driver");

Any ideas?

Thanks in advance
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
i run into a similar problem: i unziped the driver jar and added the 'com.etc.' package to classpath, but i guess this is a brute force way


java amateur
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

I'm not sure why it isn't found, are you running a web application (eg Tomcat)?

One way which may fix it is to move the JAR up one directory to C:\Program Files\Java\jdk1.5.0_05\jre\lib\ext rather than in the mysql-connector-java-3.1.12 directory.

This will add the classes as an extension to the JRE and it is an incredibly brute force way to go about things. It's about as public as you can possibly make a library, which isn't necessarily a good thing. (Oh, you can also remove it from you class path since the classes will be discovered and made available in the same way that the Core Java rt.jar classes are discovered.)

But at this stage lets just aim to get it working.
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
sorry to interrup the main thread, but just to say in my case is a stand alone java app
stu derby
Ranch Hand

Joined: Dec 15, 2005
Posts: 333

are you running a web application (eg Tomcat)?


Or an IDE, such as NetBeans or Eclipse? Projects in those have a different way of setting classpath.
Maximilian Xavier Stocker
Ranch Hand

Joined: Sep 20, 2005
Posts: 381
Originally posted by Paul Hoffman:
[QB]Hi Folks,
I have downloaded the MySQL/J Connector. I have updated my CLASSPATH so that it points to:


Incorrect. Configuring a classpath environment variable will have no effect on your servlet engine.

Consult the docs for your servlet engine to find out how to use additional jars to it's classpath.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JDBC and MySQL Problem
 
Similar Threads
MySql Driver
No suitable driver
Using jdbc from jsp with MySQL
How to install mysql for java
classNotFoundException for Driver