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

From: philfrei(at)aol(dot)com
To: pgsql-jdbc(at)postgresql(dot)org
Subject: jdbc works in java app, fails in servlet: "no suitable jdbc found"
Date: 2010-06-02 04:56:22
Message-ID: 8CCD02714A2791E-E2C-7A83@webmail-m042.sysops.aol.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

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

Is a different driver needed in the "Servlet" context? I've done
everything I can think of to make the Java Application which works and
the Java Servlet which fails as similar as possible, down to hardcoding
them both to the same "database.properties" text file. This file
contains the following data:

jdbc.url=jdbc:postgresql:gpsdata
jdbc.password=********
jdbc.username=postgres
jdbc.drivers=org.postgresql.Driver

If I understand correctly, the third parameter of the URL defaults to
//localhost:5432/gpsdata, which I can confirm is the location given by
inspection in pgAdmin III. I've tried writing out the full url, and
gone so far as to make sure everything is lowercase. But as I said, the
same connection that will work in a Java application will not work in
the servlet context.

In researching your archives, I came across another individual with the
"no suitable driver" problem. His closing comments included this:

>>The problem had nothing to do with it being a web application
(because you don't have to deploy it to generate a database schema) but
you did put me onto the right train of thought. The problem was that
although I had added the postgresql jdbc driver to my maven project as
a dependency, I hadn't added it as a dependency for the
hibernate3-maven-plugin.<<

But I'm not sure how I can apply that (I'm not using Maven, etc.),
except to ask if there are dependancies I am overlooking? Is there,
perhaps, something in the configuration of Apache that might be
omitted? Something I'm supposed to put in the web.xml file? In both the
application and the servlet, the jdbc is connected as a library, via
Eclipse's "Data Management/Connectivity/Driver Definitions" section of
the preferences. And if one right-click's and selects the properties of
the connected library in each project, the library is designated as a
"Connectivity Driver Definition".

jdbc I am using: postgresql-8.4-701.jdbc4.jar

Many thanks in advance for any assistance!

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Craig Ringer 2010-06-02 06:02:49 Re: jdbc works in java app, fails in servlet: "no suitable jdbc found"
Previous Message Lew 2010-06-01 23:38:32 Re: Not able to connect to postgresql database