Sunday, December 9, 2012

java.sql.SQLException: No suitable driver Exception

Just a quick note, if you are seeing

 java.sql.SQLException: No suitable driver ...
although you are pretty sure you have :-
  • Got the jdbc connection information correct
    • db username
    • db password
    • db url
    • db driver class
  • Got the driver jar file in the classpath for your web all
  • You are using connection pooling such as c3p0 or commons-pool
It might be time to try sticking that jdbc driver jar file into the servlet container's global classpath. This approach seems to work well in my case. Haven't dig into connection pooling code but this is my guess. When the connection pool starts up it tries to register the jdbc Driver using perhaps
  Class.forName("... jdbc driver....");
and for some reason seems to be loading it through system classloader hence if our jdbc driver jar file is in our webapp level, it's being missed causing this exception.

Hopefully, this helps whoever hits this issue.

Cheers

1 comment: