From: Craig Ringer <craig@postnewspapers.com.au>
To: philfrei@aol.com
Cc: pgsql-jdbc@postgresql.org
Subject: Re: jdbc works in java app, fails in servlet: "no suitable jdbc found"
Date: Wed, 02 Jun 2010 14:02:49 +0800
Message-ID: <4C05F409.7060805@postnewspapers.com.au> (raw)
In-Reply-To: <8CCD02714A2791E-E2C-7A83@webmail-m042.sysops.aol.com>
References: <8CCD02714A2791E-E2C-7A83@webmail-m042.sysops.aol.com>
On 02/06/10 12:56, philfrei@aol.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:
this.getClass().getClassLoader().loadClass('org.postgresql.Driver');
--
Craig Ringer
Tech-related writing: http://soapyfrogs.blogspot.com/
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-jdbc@postgresql.org
Cc: craig@postnewspapers.com.au, philfrei@aol.com
Subject: Re: jdbc works in java app, fails in servlet: "no suitable jdbc found"
In-Reply-To: <4C05F409.7060805@postnewspapers.com.au>
References: <8CCD02714A2791E-E2C-7A83@webmail-m042.sysops.aol.com> <4C05F409.7060805@postnewspapers.com.au>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox