the JDBC Driver has been forcibly unregistered

My Tomcat instance keeps complaining about de-registration failures of JDBC drivers whenever my web app re-deployed.

The web application [some-fine-webapp] registered the JDBC driver [some.nasty.JdbcDriver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.

This is actually not a problem. That message means that the Tomcat took care of something by himself.

I pay or I owe.

public class MyServletContextListener implements ServletContextListener {

    public void contextInitialized(final ServletContextEvent sce) {

    public void contextDestroyed(final ServletContextEvent sce) {
        // Is this safe? De-registering while enumerating?
        for (final Enumeration<Driver> drivers = DriverManager.getDrivers();
             drivers.hasMoreElements();) {
            try {
            } catch (final SQLException sqle) {

Well, well, well.

Collections.list(DriverManager.getDrivers()).forEach(d -> {
    try {
    } catch (final SQLException sqle) {

One comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s