Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

No suitable driver found / Tomcat 7

 
K.C. Brawley
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've been messing with this for hours now and could really use some assistance. Here's the skinny:

Postgres ver: 9.1.9, Tomcat version 7.0.26, and Java version 1.7.0_25, OS Ubuntu 12.04 - I'm trying to connect to the database using JDBC version 4. The .jar file is located in $CATALINA_HOME/lib. I receive the "No suitable driver found..." message in the logs and of course this: http://pastebin.com/wCec85bN

My dev environment is Windows 7, Tomcat 7.0.12, same JDBC driver, and Java 1.7.0.

The path to the JDBC driver is in /etc/environments in the CLASSPATH.

Also:



From everything I've read I don't need to use Class.forName(org.postgresql.Driver) with JDBC 4. I've tried it anyway and always get a "class not found exception" error.

The JDBC jar file in $CATALINA_HOME/lib is the only one not linked, I notice. I wonder if this has something to do with it (not being linked)?

Works great in my Dev environment; not so much on my VPS

 
Claude Moore
Ranch Hand
Posts: 828
7
IBM DB2 Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all I'd suggest you to include your JDBC jars in WEB-INF lib directory... I'm not a Tomcat expert but as far as I know it's better avoiding to add specific jar libraries to a Java webserver general classpath.
What happens if you try to register your Driver using DriverManager.registerDriver method ? Does it work or not ?

 
Rob Spoor
Sheriff
Pie
Posts: 20744
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
K.C. Brawley wrote:From everything I've read I don't need to use Class.forName(org.postgresql.Driver) with JDBC 4.

That's a myth. JDBC allows the ServiceLoader mechanism to be used, but only if the driver JAR file support it. The PostgreSQL driver does however.

That said, the following from the DriverManager Javadoc is very important (emphasis added by me):
When the method getConnection is called, the DriverManager will attempt to locate a suitable driver from amongst those loaded at initialization and those loaded explicitly using the same classloader as the current applet or application.

From what I could see in the Java 7 source code, the initialization uses the java.sql.Driver class' class loader. In other words, I wouldn't trust the ServiceLoader mechanism if the JAR file is loaded by any other class loader.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic