-1

I ran "mvn install..." on ojdbc7.jar, added it as a dependency to a maven project, wrote a function that connects to the database, tested it, and it worked.

I opened a new spring mvc project, added the above project as maven dependency and also to "Deployment Assembly", and called the function that I wrote that connects to the database.

When I run it in my pivotal tc server (eclipse built-in server), everything works until it reaches the line in the other project that tries to connect to the database, at which point it throws :

HTTP Status 500 - Request processing failed; nested exception is java.sql.SQLException: No suitable driver found for <the url of my database>

this means that it is not searching for the driver in my ojdbc7.jar, even adding it as a maven dependency to my spring project didn't help.

I do see the ojdbc7 jar in target\buildcenter-1.0.0-BUILD-SNAPSHOT\WEB-INF\lib, so it does add it when it compiles, but still doesn't find the driver, so there must be some configuration problem.

Any idea how to solve this?

Gilad Baruchian
  • 930
  • 3
  • 14
  • 30

1 Answers1

0

Found the problem! I hope it will help others :

In my regular maven project, I used

DriverManager.getConnection(connectionString, connectionProps);

This java.sql.DriverManager class has a static initialization that loads the ojdbc driver, for some unknown reason it works when I ran it as java application but not when I run it in spring (if anyone has any guess why please let me know).

The solution is to load the driver myself using:

Class.forName("oracle.jdbc.driver.OracleDriver");
Gilad Baruchian
  • 930
  • 3
  • 14
  • 30
  • 1
    It is not loaded if the driver is part of the web application deployment, instead of the tomcat/application server/etc. `DriverManager` only loads the drivers available on the global system classloader, not the context classloaders of the deployed web application(s). – Mark Rotteveel Oct 21 '16 at 11:23