Skip site navigation (1) Skip section navigation (2)

Re: jdbc works in java app, fails in servlet: "no suitable jdbc found"

From: Craig Ringer <craig(at)postnewspapers(dot)com(dot)au>
To: philfrei(at)aol(dot)com
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: jdbc works in java app, fails in servlet: "no suitable jdbc found"
Date: 2010-06-02 06:02:49
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-jdbc
On 02/06/10 12:56, philfrei(at)aol(dot)com wrote:
> Hi - I am new to Postgresql (and Eclipse and Tomcat--triple threat),and
> would have posted this question in the general section, but thought it
> might be more appropriate here since it concerns the JDCB.
> I have successfully installed and run some example programs from Core
> Java II by Horstmann. I wish to connect to a database from a Java
> Servlet, and tried using the same code and properties as is being used
> in a Java application program (which successfully connects to the same
> db), but am getting the following error when executing the
> DriverManager.getConnection(url, username, password) code:
> java.sql.SQLException: No suitable driver found for jdbc:postgresql:gpsdata

The JRE's JDBC is complaining that it doesn't know what to do with URLs
of type 'jdbc:postgresql'. This means that the PostgreSQL JDBC driver
hasn't been loaded.

You need to preload the PostgreSQL driver, org.postgresql.Driver , to
register it with JDBC so that JDBC knows to use it for 'postgresql' URLs.

Load the JDBC driver with with 'Class.forName' if it's on the System
classpath, or (preferably) the classloader that loaded your servelet.

> Is a different driver needed in the "Servlet" context?

No, but you might need to load it differently if your container doesn't
use the system classloader.

You can use the classloader that loaded the currently running object with:


Craig Ringer

Tech-related writing:

In response to


pgsql-jdbc by date

Next:From: Jason TesserDate: 2010-06-02 09:20:54
Subject: Re: Found a Bug in latest Driver (I THINK) and pg 8.4
Previous:From: philfreiDate: 2010-06-02 04:56:22
Subject: jdbc works in java app, fails in servlet: "no suitable jdbc found"

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group