Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JDBC and MySQL Problem

 
Paul Hoffman
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry to interrup the main thread, but just to say in my case is a stand alone java app
 
stu derby
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 381
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic