aspose file tools*
The moose likes Servlets and the fly likes mysql JDBC driver classpath problem. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "mysql JDBC driver classpath problem." Watch "mysql JDBC driver classpath problem." New topic
Author

mysql JDBC driver classpath problem.

Sudharsan Govindarajan
Ranch Hand

Joined: Jul 03, 2002
Posts: 319
Hi!
I have a .jar in my WEB-INF\lib directory. It has a DBConnection class which makes use of the mySQL JDBC driver. I have put the driver .jar (mysql_comp.jar) in the same 'lib' folder. But it fails to recognize the class and throws the exception,

What could be the issue?
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Sudharsan,
Please take some time to go through a JDBC tutorial. There is a good one on the sun web site:
JDBC Database Access
In the page 3 of the basic tutorial, you learn that in order to create a connection, you first need to load your driver in memory.
In your case, this means:

Please note however that the MM distribution of the MySQL JDBC driver is not supported anymore. Look at the MySQL web site for more details.
Cheers
Sudharsan Govindarajan
Ranch Hand

Joined: Jul 03, 2002
Posts: 319
Hi!
Thanks for the JDBC tutorial link :-). But I'm not a newbie to JDBC. I'm new to Tomcat's environment.
I don't get an Exception at the Class.forName() statement. But the Eception is thrown when i try to getConnection() from DriverManager. Should the old mm driver be an issue?
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Sudharsan,
The driver is probably an issue. One of the reasons why it doesn't work could be that the driver does not register itself in a static block.
So you could try the following:

Hope this helps
[ December 20, 2002: Message edited by: Beno�t d'Oncieu ]
Sudharsan Govindarajan
Ranch Hand

Joined: Jul 03, 2002
Posts: 319
Beno�t!
Thanks for ur code. But it still does'nt solve the problem. I've tried with both the drivers, mm and mySQL Connector/J.
This is the error I get,

This is the code snippet

The jar in which the DBConnection class is packaged and the mysql drivers are in the same folder i.e., TOMCAT_ROOTwebapps\ROOT\WEB-INF\lib
thanks
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
OK, got it.
The mysql_comp.jar corresponds to the "org.gjt.mm.mysql.Driver" JDBC driver.
The "com.mysql.jdbc.Driver" driver you are refering to is located in another library (name: mysql-connector-java-2.0.14-bin.jar). You may download it from the MySQL Download Connector/J web page.
Cheers
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
You may also want to make sure an instance of mySQL is up an running.


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
Sudharsan Govindarajan
Ranch Hand

Joined: Jul 03, 2002
Posts: 319
No Beno�t! I have both the mm driver and mysql driver .jars in my lib directory. If my mySQL server is not running, I should get a different Exception. I'm still trying to figure out what could be the problem
Jignesh Patel
Ranch Hand

Joined: Nov 03, 2001
Posts: 626

DO one thing,
Unjar the file and tell me what happens.
I think this is a path resolution problem.
-jignesh
Sudharsan Govindarajan
Ranch Hand

Joined: Jul 03, 2002
Posts: 319
you mean unjar the application.jar and put them in the myApp\WEB-INF\classes folder? Or do u want me to unjar the jdbcdriver jar?
Brad Morton
Greenhorn

Joined: Jan 03, 2003
Posts: 1
I had a similar problem and was pulling my hair out for a while. I was receiving the "No suitable driver found" (or something like that) when trying to connect to my MySQL database.
The answer was in the db url. Try using the following format:
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost/dbname", "user", "password");
(Note the "://" after jdbc:mysql. This is what differed from the documentation I was following)
Once I made the above change, I started getting authentication errors which I then resolved within MySQL using the following commands:
prompt$ mysql -u root -p mysql
mysql> grant select,insert,update,delete,etc on dbname.* to user@host identified by 'password';
mysql> grant usage on *.* to user@host;
mysql> flush privileges;
Substitute "user", "password" and "host" as appropriate.
I hope this helps.
Cheers,
Brad.
Sudharsan Govindarajan
Ranch Hand

Joined: Jul 03, 2002
Posts: 319
Brad!
my URL is alright. And my user has the required permissions. I've did a unjar of may application and put that in my WEB-INF\classes folder. Nothing seems to help...

sudharsan
------------------------------
Joy is a radiation
Ryan Bailey
Ranch Hand

Joined: Feb 26, 2002
Posts: 134
Hi sudharsan,
If you downloaded the zip file from
http://www.mysql.com/downloads/download.php?file=Downloads/Connector-J/mysql-connector-java-2.0.14.zip then unzip the mysql-connector-java-2.0.14.zip file and then go into the mysql-connector-java-2.0.14 file and the jar file you are looking for is called mysql-connector-java-2.0.14-bin.jar. Include that in your classpath and load the Class.ForName() with the following parameter... com.mysql.jdbc.Driver.
I have ran into this error multiple times and I believe this is happening for one of two reasons. One, you have inserted the parameter in the Class.forName() incorrectly, Two, you do not have the jar file(mysql-connector-java-2.0.14-bin.jar) set correctly in your path. Hope this helps.
Cheers,
Ryan


SCJP 1.4, SCWCD
Java: The power, elegance, and simplicity of a hand grenade
Sudharsan Govindarajan
Ranch Hand

Joined: Jul 03, 2002
Posts: 319
Ryan,
I have the 'mysql-connector-java-2.0.14-bin.jar' in my \WEB-INF\lib folder.
And the parameter to Class.forName() is exactly 'com.mysql.jdbc.Driver'.
But I still get the error. I've even removed my Tomcat installation and re-installed
it..
Nothing seems to be help. May be I'm missing a very small point..
thanks
Sudharsan
Sudharsan Govindarajan
Ranch Hand

Joined: Jul 03, 2002
Posts: 319
I implemented Connection Pooling using JNDI. The JNDI solution solved my problem. I'm now able to get a Connection.
But without JNDI, the 'No Suitable Driver' problem still persists.
sudharsan
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: mysql JDBC driver classpath problem.