JDBC drivers register in a single, single JVM DriverManager format, which is used by all web applications. If you have the same name (for example, a class name), the JDBC driver is registered twice from two different web applications, this may lead to your problem. This is even more problematic if your web applications use different versions of the same JDBC driver.
In addition, placing JDBC drivers in the Tomcat lib folder will help prevent memory leaks when you redeploy your web application without restarting Tomcat, for example. if you just put the new WAR file in the Tomcat webapps folder:
The DriverManager class DriverManager loaded by the bootstrap class loader and thus "lives" globally in the JVM, and Tomcat loads all web applications into its own class loaders. So if the JDBC driver from the WEB-INF web application / lib folder is registered in the DriverManager , it links this web application class loader in memory (and thereby all classes of this web application), preventing garbage collection.
If instead both DriverManager and JDBC drivers come from classes other than web applications, you can freely swap your web applications without any classes of web applications fixing themselves to classes loaded from other class loaders.
Current versions of Tomcat (possibly 6.x and specifically 7.x) will log warnings when deploying a web application if a memory leak is detected, among other things, by JDBC drivers.
Philipp Reichart Aug 25 2018-11-21T00: 00Z
source share