• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Why can't Tomcat/servlet load MySQL driver? Its in classpath..

Schrodinger

Golden Member
I'm writing a servlet and testing it locally with Tomcat
Part of it has some db access and connects to a remote MySQL server that I don't host.

When I even try to load the driver it throws an exception (ClassNotFoundException). It has nothing to do with remote connectivity or anything like that because I can't even get the damn driver to load.

Weird thing is that it is in my CLASSPATH and little java apps I'm writing and testing have no problem launching it?

🙁
 
When you execute stuff in a container like tomcat you can always expect the classpath to change. I wasn't aware that things on the system CLASSPATH would actually be innaccessible but I'd be willing to bet that's your problem. There are designated places for you to put third party jars and tomcat will automatically make them accessible to your applications. If it should be globally accessible to all webapplications put it in CATALINA_HOME/common/lib. If you want the drive packaged with your application only put it in WEB-INF/lib.

On this topic, I'm guessing from the nature of your post that you're going the Class.forName(), and DriverManager route. That's a possiblilty for desktop apps but it really shouldn't be used for web applications. Some sort of connection pool is necessary. Tomcat 5.0 includes a primitive version which is explained here. The mysql driver itself includes a better one. If you are interested in setting that up I can try to remember how I did it...

I just noticed that Tomcat 5.5 is out; I don't know what it includes in the way of connection pools.
 
You have to copy MySQL drive to tomcat lib directory. Not sure what the driver file is named for MySQL. For DB2 it's db2java.zip, for oracle its classes12.jar.
 
Back
Top