tags:

views:

98

answers:

1

I have set a JDBCRealm for web-app inside tomcat, and when I reload it I got this from tomcat:
SEVERE: A web application registered the JBDC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.

I use tomcat 6.0.24, with MySQL Connector 5.1.10,,,

Is there a way to clean it up, so tomcat won't display SEVERE message?

A: 

This is not a leak, or at least it is one that does not matter. If you have a singleton object (The JDBC driver) and it is never released until the app finishes, does it matter ?
The database will close any pending connections after a given amount of time.

If it really bothers you, you could fix it by overriding close method this way:

public class XBasicDataSource extends BasicDataSource {
    @Override
    public synchronized void close() throws SQLException {
        DriverManager.deregisterDriver(DriverManager.getDriver(url));
        super.close();
    }
}

And use your XBasicDataSource .

Romain Hippeau
Where should I inject this piece of code?
mabuzer
@mabuzer Create a Jar file and put it in the lib folder for Tomcat. Use this as your DataSource
Romain Hippeau
cool, it's working, thanx Romain
mabuzer