• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Bear Bibeault
  • paul wheaton
Saloon Keepers:
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Mikalai Zaikin
  • Piet Souris
Bartenders:

No suitable driver found / Tomcat 7

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Bartender
Posts: 1342
39
IBM DB2 Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ?

 
Sheriff
Posts: 22755
130
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
So I left, I came home, and I ate some pie. And then I read this tiny ad:
Low Tech Laboratory
https://www.kickstarter.com/projects/paulwheaton/low-tech-0
reply
    Bookmark Topic Watch Topic
  • New Topic