Connecting to DB2 running on Mainframe RACF

Copy db2jcc.jar file to WEB-INF/lib and use com.ibm.db2.jcc.DB2Driver as JDBC Driver.

It is best to put JDBC driver into Tomcat’s lib directory instead, if there is a chance you will have another web application running in the same Tomcat server.

The StackOverflow answer stated memory-leak as a reason. There is actually another reason to not put JDBC drivers inside any web application.

In my previous job, a vendor made the same mistake of putting JDBC driver in IdentityIQ’s WEB-INF/lib folder. The database was MS SQL, and integrated authentication was used. MS SQL implements integrated authentication via a native library, invoked from MS SQL JDBC driver via JNI.

Which means, when loading the MS SQL JDBC driver, it will load a native library in turn.

Later, when another database-using web application was introduced, this new application would startup faster than IdentityIQ. The JDBC driver got loaded into the VM (under this web application’s classloader), and the MS SQL native library as well (under the JVM).

Then when it is IdentityIQ’s turn, it tries to load the JDBC driver again. The Java part loaded successfully (under IdentityIQ’s classloader), but the native library won’t, because JVM only allows a single instance of a native library, regardless of which classloader you are using. And so IdentityIQ fail to create any JDBC connection.

Putting the MS SQL JDBC driver into Tomcat\lib will load the JDBC driver exactly once (under Tomcat’s classloader). Then both web applications can use it.

So in short, put JDBC drivers in Tomcat\lib, not inside any web applications. It will probably save you from future headaches.

1 Like