Question

This is a kind of driving me nuts, I found some similar questions here on SO but I can't get it to work.

I have a multi project spring (web) project. It starts fine, but as soon as I want to query the db I get a

Nested in org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: 
Cannot create JDBC driver of class 'oracle.jdbc.OracleDriver' for connect URL 'jdbc:oracle:thin//server:1521:XE':

I tried many things: I made sure the ojdbc.jar is inside my project (not part of maven repo so I loaded it with gradle like

compile files('lib/websphere_apis.jar','lib/ojdbc14.jar') 

in my sub (not web) or in my web project.

Which gets the jars inside war when I generate them with with gradle war

I tried adding the jars to the jettyRun configuration with

jettyRun {
   additionalRuntimeJars = files('lib/ojdbc14.jar')
}

I'm a bit in doubt whether the files stmt is correct but still it doesn't work.

I also found on SO that I should put

   providedRuntime files("$projectDir/../lib/ojdbc14.jar")

inside my webapp as a standard dependency but that still doesn't work for me. I have used postgres driver jars before which I could just include as a dependency.

Was it helpful?

Solution

With JDBC .jar files, if you are not careful about where you load the .jar on the classpath, you might get an error like what you are seeing. If you want to be sure, pass the .jar on the classpath as an argument to the main JVM that is calling the program. The reason is that you need to make sure the .jar class files are loaded in the "default JVM classloader". If you try to load JDBC .jars dynamically through other means ( perhaps even as OSGI) , or dynamically loaded by custom classloader like Tomcat has, then you could get class loader issues.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top