1

I am unit-testing my jersey web-service through jersey client using eclipse Oxygen.3a, Tomcat 9, JDK 1.8, and ojbc14.jar in my WEB-INF/lib of my web-app in eclipse. I do not have any ojdbc.jar's in my Tomcat/lib dir. So there is single copy of my ojdbc jar file, i.e. ojdbc14.jar. My JDBC URL is jdbc:oracle:thin:@mcname.com:1521:orcl1.

My request is failing due to the following error:

Exception when obtaining connection java.sql.SQLException: No suitable driver at java.sql.DriverManager.getDriver(DriverManager.java:315) at :

Code:

DriverManager.getDriver("jdbc:oracle:thin:@" + url);
Karol Dowbecki
  • 43,645
  • 9
  • 78
  • 111
Soumali Chatterjee
  • 309
  • 1
  • 4
  • 13

1 Answers1

0

You are using an old Java 1.4/1.5 OJDBC driver with JDK 1.8. You should update the JAR to ojdbc8.jar as per What are the Oracle JDBC releases versus JDK versions?. Running an outdated OJDBC driver is not a good idea, if you get java.sql.SQLException: No suitable driver it means that driver registration might have failed.

Do note that if your url variable is jdbc:oracle:thin:@mcname.com:1521:orcl1 than the code becomes

DriverManager.getDriver("jdbc:oracle:thin:@jdbc:oracle:thin:@mcname.com:1521:orcl1);

and the URL duplicates jdbc:oracle:thin:@. Do check that you are creating the URL correctly.

Karol Dowbecki
  • 43,645
  • 9
  • 78
  • 111
  • ok, now I am using Java 7, as there were some other dependencies, with asm.jar. So configuration now, is Jersey 1.10, Tomcat 9, JDK 1.7, ojdbc7.jar. Still getting same exception as above: **java.sql.SQLException: No suitable driver at java.sql.DriverManager.getDriver(DriverManager.java:315)** `My code flow is: `DriverManager.getDriver(url); }catch (SQLException e) { String urlStr="jdbc:oracle:thin:@" + url; DriverManager.getDriver(urlStr);` – Soumali Chatterjee Aug 05 '18 at 18:11
  • So, I am testing for both the scenarios `1)DriverManager.getDriver("mcname.com:1521:orcl1") 2)If above code throws exception, then try below code: DriverManager.getDriver("jdbc:oracle:thin:@mcname.com:1521:orcl1")` – Soumali Chatterjee Aug 05 '18 at 18:20
  • @SoumaliChatterjee `jdbc:oracle:thin:@mcname.com:1521:orcl1` is the right URL. You need to debug `Driver.getDriver(String)` method to figure out why it's not working. – Karol Dowbecki Aug 05 '18 at 18:47
  • I tried DriverManager.getDrivers(), in order to get the list of JDBC drivers which are loaded, it prints nothing. This means no drivers have got loaded – Soumali Chatterjee Aug 06 '18 at 02:43