Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why must the JDBC driver be put in TOMCAT_HOME/lib folder?

Tags:

tomcat

jdbc

I have a weird problem where two web apps with Oracle JDBC driver will conflict with each other. I have to put the JDBC driver JAR in the common folder TOMCAT_HOME/lib. What is the reason for this?

like image 374
zjffdu Avatar asked Aug 08 '11 11:08

zjffdu


People also ask

Where do I put my JDBC driver?

The JDBC driver files are installed in C:\program files\microsoft SQL server <ver> JDBC Driver\lib.

What is the path of JDBC drivers?

x-bin. jar) JDBC driver is installed with WebLogic Server. This driver is installed in the WL_HOME \server\lib folder (where WL_HOME is the folder where WebLogic Server is installed) with weblogic.

Where is JDBC driver in Linux?

The JDBC driver is typically located at the location WL_HOME/server/lib of the installation directory. The file is ojdbc7. jar or ojdbc6. jar (for new versions of WLS), or ojdbc14.

What is JDBC driver file?

The Microsoft JDBC Driver for SQL Server is a Type 4 JDBC driver that provides database connectivity through the standard JDBC application program interfaces (APIs) available on the Java platform. The driver downloads are available to all users at no extra charge.


1 Answers

JDBC drivers register themselves in the JVM-wide singleton DriverManager which is shared by all web apps. If you have the same (as in class name) JDBC driver register twice from two different web apps, this might cause your problem. This is even more problematic if your web apps use different versions of the same JDBC driver.

Also, putting JDBC drivers into Tomcat's lib folder will help prevent memory leaks when you redeploy your web app without restarting Tomcat, e.g. if you just put a new WAR file into Tomcat's webapps folder:

The class DriverManager gets loaded by the bootstrap classloader and thereby "lives" globally in the JVM, while Tomcat loads all web apps in their own classloaders. So if a JDBC driver from a web app's WEB-INF/lib folder registers itself in DriverManager, it pins that web app's classloader in memory (and thereby all the classes of that web app), preventing its garbage collection.

If instead both DriverManager and JDBC drivers come from non-web app classloaders, you can freely redeploy your web apps without any web app classes pinning themselves in classes loaded from other classloaders.

Current versions of Tomcat (probably 6.x and definitely 7.x) will log warnings on undeployment of a web app if a memory leak is detected, among other things by JDBC drivers.

like image 157
Philipp Reichart Avatar answered Oct 22 '22 10:10

Philipp Reichart