You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by bu...@apache.org on 2009/12/21 15:13:20 UTC

DO NOT REPLY [Bug 48214] JDBC DriverManager: no suitable driver found after context reload

https://issues.apache.org/bugzilla/show_bug.cgi?id=48214

--- Comment #2 from Mark Thomas <ma...@apache.org> 2009-12-21 06:13:16 GMT ---
The problem you are seeing is a result of where you have placed the driver
class, how DriverManager works internally and what Tomcat now does to prevent
memory leaks.

Your driver class is in CATALINA_HOME/lib so will be loaded by Tomcat's common
class loader. The sequence of events is:

- Tomcat starts
- Your app starts
- Your servlet is loaded and init() runs
- The driver class is loaded due to the Class.forName() call
- The common class loader loads the class
- The class is registered with DriverManager but as DriverManager uses the
context class loader, it is registered against your web application
- The app runs for a while
- The app is reloaded
- Tomcat spots that DriverManager has registered the JDBC driver against the
webapp class loader
- Tomcat unregisters the JDBC driver to prevent a memory leak
- Your app restarts
- Your servlet is loaded and init() runs
- The driver class is not loaded since it was loaded by the common class loader
and is, therefore, still available
- No class is loaded, so no driver is registered with DriverManager
- init() fails when DriverManager can't find the driver

There are many ways to fix this. The simplest are:
- use a context listener to explicitly call DriverManager.register and
deregister()
- move the JDBC driver to WEB-INF/lib

Tomcat 7 logs a message when unregistering the JDBC driver that provides a
useful clue as to what is going on. Tomcat 6 doesn't do that. I'll propose the
necessary changes for inclusion in Tomcat 6.

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org