Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

"Unable to Load Driver" - MySQL

 
Paid O'Cuana
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a JDBC connection running ok on my own machine, and I've been transferring it over to the company server. I seem to have everything in place, put the thing breaks down on my Db connection. I'm using a MySQL db with the mm.mysql-2.0.11 driver. I'm using the Jakarta-tomcat3.3 webserver.
The problem happens here:
try
{
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
}
catch (Exception E) {
System.err.println("Unable to load driver.");
E.printStackTrace();
}
I get the "Unable to load driver" message.
Now, I have my CLASSPATH going to the /usr/local/jdk1.3.1/lib/mm.mysql-2.0.11 directory where the org/gjt/mm/mysql/Driver.class stuff originates from.
I also tried putting
/usr/local/jdk1.3.1/lib/mm.mysql-2.0.11/mm.mysql-2.0.11-bin.jar in the CLASSPATH, but it doesn't work either.
This all works fine on my localhost:8080, but I've thrown it onto the company server, and it breaks. Can anyone help?
 
Tarun Ramakrishna Elankath
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
My experience is with Tomcat 4, so please don't take everything at heart.
Tomcat 4 offers a connection pool so that I don't need to mess with Class.forName and DriverManager.
For Tomcat 3 I suggest putting your driver.jar file in WEB-INF/lib and try again. I do not know whether Tomcat 3 offers a Connection Pool.
Another bit of advice, do _not_ catch Exception. Its bad design. The class.forName().newInstace() stuff will throw 3 exceptions. Catch all of them in different catch blocks and react accordingly.
Hope that helps,
Tarun
 
Philip Shanks
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Two suggestions:
1) Upgrade to latest Connector/J driver for MySQL
2) Use the getConnection(user, pwd) method of the DataSource class, and stop wrestling with the java.sql.DriverManager class.
Your resulting code may look something like this:

Just be sure that you have mysql-connector-java-3.0.7-stable-bin.jar in your classpath, and enjoy the magic!
[ May 19, 2003: Message edited by: Philip Shanks ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic