1

I am trying to run a simple java web app that connects to a back end DB2 database(IBM dashdb) to get retrieve some data.

I am getting a weird error message when I try to run this application on a ubuntu hosted tomcat 8.5. I managed to get this application running on a tomcat v8 hosted on Windows.

The actual error message is:

No suitable driver found for jdbc:db2://yp-dashdb......

I don't really understand why this is happening because I have the db2jcc4. in my web-inf\lib folder. enter image description here

I thought it was something wrong with the library so I created a separate Java app to simply connect and retrieve some data from the database. That one works just fine with the same library.

This is the code used to set up the connection (I trimmed out some of the details).

private Connection conn = null;   
conn= DriverManager.getConnection("jdbc:db2://yp-dashdb...");

Keep in mind, that this exact same code works in a Standard Java app so the connection details work and there's no typo in the connection info.

Is there something obvious that I'm overlooking here?

sir_k
  • 332
  • 3
  • 18
  • What version of the jar do you have? Does the jar file contain a file named `META-INF/services/java.sql.Driver`? What version of Java are you using? – Andreas Nov 08 '16 at 23:12
  • Hey, as mentioned above. This exact same jar worked on a different tomcat. I don't think the jar is missing anything. I'm using ibm java 1.8. – sir_k Nov 09 '16 at 06:03

2 Answers2

2

After spending some time trying to figure this one out I find out the problem. My drivers were not being registered by DriverManager. The quick fix I found for this was to manually register it before trying to load the driver.

DriverManager.registerDriver(new com.ibm.db2.jcc.DB2Driver());

This has solved my issue. The way I found out about this was to print out all the registered drivers and print them out. Not the most elegant solution but it helped me find out what I'm missing.

        /*
        System.out.println("checking for drivers");
        Enumeration<Driver> myDrivers = DriverManager.getDrivers();
        System.out.println(myDrivers.hasMoreElements());

        while(myDrivers.hasMoreElements()){
            System.out.println(myDrivers.nextElement().toString());
        }
        */
sir_k
  • 332
  • 3
  • 18
  • You deserve one thousand upvotes ! I lost an entire day because my setup was working correctly in Windows, but not on Linux, even when using the exact same version of Java's SDK! I already had discovered that the driver was not being automatically registered and that line saved my day! Appreciated – Henrique de Sousa Nov 12 '19 at 15:18
  • 1
    @HenriquedeSousa your comment just made my day. – sir_k Nov 13 '19 at 15:15
0

WEB-INF/lib is in your application. It might be so that tomcat needs this driver before your app is loaded? Try putting it into the tomcat's lib folder and restarting...

Here is another question on the same topic: Why must the JDBC driver be put in TOMCAT_HOME/lib folder?

Community
  • 1
  • 1
Igor Deruga
  • 1,504
  • 1
  • 10
  • 18