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,
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
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?
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
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
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.
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
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