Search code examples
javatomcatmybatisc3p0tomcat8

Error starting webapp with Mybatis, c3p0 on Tomcat 8


I am trying to deploy my webapp on Tomcat 8 that uses Mybatis 3.2.7 and c3p0 for connection pooling to connect to an SQLServer database. I have the sqljdbc4.jar in my classpath. I query the database during my webapp startup to get some values.

The application works in Tomcat 7, however on Tomcat 8, I cannot connect to the database. I debugged a lot using eclipse and the root cause is in the file BasicResourcePool.class file in c3p0 where it is waiting for resource to become available but then throws an java.lang.InterruptedException.

Due to this, Mybatis is throwing a java.SQL.SQLException and thus my webapp does not start as it cannot connect to the database.

Has someone else upgraded to Tomcat 8 and has successfully used Mybatis-c3p0? If yes am I missing something over here?


Solution

  • Solved this. It was JDBC driver issue. Mybatis isn't very good in showing underlying exceptions it seems.

    Found this on tomcat 8's documentation:

    Thus, the web applications that have database drivers in their WEB-INF/lib directory cannot rely on the service provider mechanism and should register the drivers explicitly.

    So, I added a Class.forName() with the appropriate driverClass during app startup and this solved my issue.