From: philfrei@aol.com
To: pgsql-jdbc@postgresql.org
Subject: jdbc works in java app, fails in servlet: "no suitable jdbc found"
Date: Wed, 02 Jun 2010 00:56:22 -0400
Message-ID: <8CCD02714A2791E-E2C-7A83@webmail-m042.sysops.aol.com> (raw)
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!
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: philfrei@aol.com
Subject: Re: jdbc works in java app, fails in servlet: "no suitable jdbc found"
In-Reply-To: <8CCD02714A2791E-E2C-7A83@webmail-m042.sysops.aol.com>
References: <8CCD02714A2791E-E2C-7A83@webmail-m042.sysops.aol.com>
* 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