0
WARNING [http-nio-8181-exec-550] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesJdbc 
The web application [comparateur] registered the JDBC 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 used this class

package servlets;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Enumeration;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
public class MyContextListener implements ServletContextListener{

@Override
public void contextDestroyed(ServletContextEvent arg0) {
System.out.println("App shutdown ...");

System.out.println("Deregistering SQL-Drivers ...");
Enumeration<Driver> drivers = DriverManager.getDrivers();
while (drivers.hasMoreElements()) {
    Driver driver = drivers.nextElement();
    try {
        DriverManager.deregisterDriver(driver);
        System.out.println(driver.getClass().getName());
    } catch (SQLException e) {
        System.err.println("Error deregistering driver " +       
   driver.getClass().getName());
    }
 }
}

 @Override
 public void contextInitialized(ServletContextEvent arg0) {
 }
 }

and my connexion with DB

private String dbName = "NameDB";
private String user = "root";
private String pass = "PWD";   
private String server = "localhost";

i have the same prob but with this message INFO [http-nio-8181-exec-579]org.apache.catalina.core.ApplicationContext.log HTMLManager: list: Listing contexts for virtual host 'localhost'

Any help appreciated.

maro
  • 1
  • 1
  • 3
  • Your method of deregistering might also deregister drivers loaded for another application. You might want to check http://stackoverflow.com/a/23912257/466862 – Mark Rotteveel Sep 14 '15 at 08:16

1 Answers1

0

It looks to me as if your ServletContextListener implementation isn't being picked up by Tomcat.

If you want your ServletContextListener implementation to be picked up by your web application container, you need to do one of two things:

  • add the @WebListener annotation to the class.
  • add the following element to your web.xml file. This element should be a child of the root <web-app> element.

    <listener>
        <listener-class>servlets.MyContextListener</listener-class>
    </listener>
    
Luke Woodward
  • 63,336
  • 16
  • 89
  • 104
  • @maro: if you had already wired up your MyContextListener in your web.xml, it would have helped to have mentioned that in your question. Going forwards, however, I would recommend removing the MySQL JDBC driver JAR from your web app's WEB-INF/lib folder and putting it only in the Tomcat lib folder. That is the standard way to avoid memory leaks with JDBC drivers in Tomcat. It also means you don't need to deregister the driver in a ServletContextListener. – Luke Woodward Sep 17 '15 at 21:06