I'm facing a weird behavior with tomcat data source and OracleConnection
Case 1:
I have configured datasource in tomcat 8 for oracle12c and placed the ojdbc8.jar in tomcat_home/lib folder.
After that I'm executing this below code and it's working
try
{
if (connection.isWrapperFor(OracleConnection.class))
{
oracleConnection = connection.unwrap(OracleConnection.class); //working fine
}
}
catch (SQLException ex)
{
}
Case 2:
configured datasource again and placed the ojdbc8.jar in tomcat_home/lib folder as well as in WEB-INF/lib of dynamic web project.
After that I'm executing same above code and it's not unwrapping the connection and i'm getting null in oracleConnection.
Why is that happening?
If this method returns true then calling unwrap with the same argument should succeed.If you're saying isWrapperFor() == false in the failing case, one possibility is that OracleConnection is being loaded by two different classloaders (one for system, ie tomcat_home/lib and one for app WEB_INF/lib) and the isWrapperFor would see those as two different classes.oracleConnectionis also null. Should I keepojdbc8.jarintomcat_home/libor in webapp folder?