Thread: Problems setting up PostgreSQL and Tomcat JDBC connection

Problems setting up PostgreSQL and Tomcat JDBC connection

From
Nikola Milutinovic
Date:
Hi all.

I'm crossposting this to two mailing lists, I think poth parties are concerned.

Finaly got some time to work on my project on Tomcat and I ran into problems.
Mostly these problems stem from the inconsistent documentation that accompanies
Tomcat 4.0 distribution. And it would appear that PostgreSQL is also in error
(see below).

I have:

- Tru64 UNIX 4.0D (a.k.a. Digital UNIX)
- Java 1.3.0 SDK
- Tomcat 4.0 final release
- PostgreSQL 7.1.0
- PostgreSQL JDBC 2.0 compliant driver

QUESTION 1: How do I go about setting it up with Tomcat?

I have tried the following:

- placed postgresql.jar in ${CATALINA_HOME}/common/lib/
- added CATALINA_OPTS="-Djdbc.drivers=postgresql.Driver"
- restarted Tomcat

My JSP file is:

<%-- My first go at PostgreSQL and JSP --%>
<%@ page info="test" import="java.sql.*, javax.sql.*" %>
<%!
Connection conn = DriverManager.getConnection(
"jdbc:postgresql://localhost/mercury", "test", "test00" );
String query = "SELECT * FROM div";
%>

[SNIP]

</html>

When I run it, I get the following error:

-------------------------------------------------------------------
org.apache.jasper.JasperException: Unable to compile class for JSP
...

Root Cause:

java.lang.NumberFormatException: postgresql
...
-------------------------------------------------------------------

This would imply that I'm either using a wrong connection string or the driver
isn't loaded, right?

QUESTION 2: Now this may sound dumb, but... PostgreSQL docs state that I should
load driver with "-Djdbc.drivers=posgresql.Driver", but if I list postgresql.jar
file, I see it is "org.postgresql.Driver". Is this a typo in the docs?

Nix.

Re: Problems setting up PostgreSQL and Tomcat JDBC connection

From
"Mihai Gheorghiu"
Date:
When I wrote a servlet for TC3.2.3, before Connection conn=bla..., I had
Class.forName("org.postgresql.driver");
As far as the location of postgresql.jar, I had it in JDK_HOME/lib and in
TOMCAT_HOME/lib at least (maybe in WEB-INF/lib as well - I can't remember)


-----Original Message-----
From: Nikola Milutinovic <Nikola.Milutinovic@ev.co.yu>
To: Tomcat Users <tomcat-user@jakarta.apache.org>; PostgreSQL
<pgsql-general@postgresql.org>
Date: Monday, October 22, 2001 4:01 PM
Subject: [GENERAL] Problems setting up PostgreSQL and Tomcat JDBC connection


>Hi all.
>
>I'm crossposting this to two mailing lists, I think poth parties are
concerned.
>
>Finaly got some time to work on my project on Tomcat and I ran into
problems.
>Mostly these problems stem from the inconsistent documentation that
accompanies
>Tomcat 4.0 distribution. And it would appear that PostgreSQL is also in
error
>(see below).
>
>I have:
>
>- Tru64 UNIX 4.0D (a.k.a. Digital UNIX)
>- Java 1.3.0 SDK
>- Tomcat 4.0 final release
>- PostgreSQL 7.1.0
>- PostgreSQL JDBC 2.0 compliant driver
>
>QUESTION 1: How do I go about setting it up with Tomcat?
>
>I have tried the following:
>
>- placed postgresql.jar in ${CATALINA_HOME}/common/lib/
>- added CATALINA_OPTS="-Djdbc.drivers=postgresql.Driver"
>- restarted Tomcat
>
>My JSP file is:
>
><%-- My first go at PostgreSQL and JSP --%>
><%@ page info="test" import="java.sql.*, javax.sql.*" %>
><%!
>Connection conn = DriverManager.getConnection(
>"jdbc:postgresql://localhost/mercury", "test", "test00" );
>String query = "SELECT * FROM div";
>%>
>
>[SNIP]
>
></html>
>
>When I run it, I get the following error:
>
>-------------------------------------------------------------------
>org.apache.jasper.JasperException: Unable to compile class for JSP
>...
>
>Root Cause:
>
>java.lang.NumberFormatException: postgresql
>...
>-------------------------------------------------------------------
>
>This would imply that I'm either using a wrong connection string or the
driver
>isn't loaded, right?
>
>QUESTION 2: Now this may sound dumb, but... PostgreSQL docs state that I
should
>load driver with "-Djdbc.drivers=posgresql.Driver", but if I list
postgresql.jar
>file, I see it is "org.postgresql.Driver". Is this a typo in the docs?
>
>Nix.
>
>---------------------------(end of broadcast)---------------------------
>TIP 4: Don't 'kill -9' the postmaster


Re: Problems setting up PostgreSQL and Tomcat JDBC connection

From
Barry Lind
Date:
What docs are you reading that say this?  This used to be the case in
6.5 of postgres, but the main class has been org.postgresql.Driver since
7.0.

thanks,
--Barry


Nikola Milutinovic wrote:

> Hi all.
>
> I'm crossposting this to two mailing lists, I think poth parties are concerned.
>
> Finaly got some time to work on my project on Tomcat and I ran into problems.
> Mostly these problems stem from the inconsistent documentation that accompanies
> Tomcat 4.0 distribution. And it would appear that PostgreSQL is also in error
> (see below).
>
> I have:
>
> - Tru64 UNIX 4.0D (a.k.a. Digital UNIX)
> - Java 1.3.0 SDK
> - Tomcat 4.0 final release
> - PostgreSQL 7.1.0
> - PostgreSQL JDBC 2.0 compliant driver
>
> QUESTION 1: How do I go about setting it up with Tomcat?
>
> I have tried the following:
>
> - placed postgresql.jar in ${CATALINA_HOME}/common/lib/
> - added CATALINA_OPTS="-Djdbc.drivers=postgresql.Driver"
> - restarted Tomcat
>
> My JSP file is:
>
> <%-- My first go at PostgreSQL and JSP --%>
> <%@ page info="test" import="java.sql.*, javax.sql.*" %>
> <%!
> Connection conn = DriverManager.getConnection(
> "jdbc:postgresql://localhost/mercury", "test", "test00" );
> String query = "SELECT * FROM div";
> %>
>
> [SNIP]
>
> </html>
>
> When I run it, I get the following error:
>
> -------------------------------------------------------------------
> org.apache.jasper.JasperException: Unable to compile class for JSP
> ...
>
> Root Cause:
>
> java.lang.NumberFormatException: postgresql
> ...
> -------------------------------------------------------------------
>
> This would imply that I'm either using a wrong connection string or the driver
> isn't loaded, right?
>
> QUESTION 2: Now this may sound dumb, but... PostgreSQL docs state that I should
> load driver with "-Djdbc.drivers=posgresql.Driver", but if I list postgresql.jar
> file, I see it is "org.postgresql.Driver". Is this a typo in the docs?
>
> Nix.
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
>
>



Re: Problems setting up PostgreSQL and Tomcat JDBC connection

From
Doug McNaught
Date:
Nikola Milutinovic <Nikola.Milutinovic@ev.co.yu> writes:

> QUESTION 2: Now this may sound dumb, but... PostgreSQL docs state
> that I should load driver with "-Djdbc.drivers=posgresql.Driver",
> but if I list postgresql.jar file, I see it is
> "org.postgresql.Driver". Is this a typo in the docs?

Yes, the package structure changed in 7.1 or thereabouts.
'org.postgresql.Driver' is the correct classname.

Have you tried writing a standalone JDBC test app just to make sure
all the database plumbing works and you've got the right connection
URL?

BTW, the current stable release of Postgres is 7.1.3, and there were
quite a few bugs fixed since 7.1.0.  You might want to consider
upgrading.

-Doug
--
Let us cross over the river, and rest under the shade of the trees.
   --T. J. Jackson, 1863

Re: Problems setting up PostgreSQL and Tomcat JDBC connection

From
"Nikola Milutinovic"
Date:
> When I wrote a servlet for TC3.2.3, before Connection conn=bla..., I had
> Class.forName("org.postgresql.driver");
> As far as the location of postgresql.jar, I had it in JDK_HOME/lib and in
> TOMCAT_HOME/lib at least (maybe in WEB-INF/lib as well - I can't remember)

Thanks. I have postgresql.jar in a proper location, it seams. Looks like it is either not getting loaded or not
registeredas a JDBC driver.
 

QUESTION 1: How can I check if a particular jar/class has been accepted by the classloader?
QUESTION 2: Again, what is the proper way of specifying a "system-wide" JDBC driver in Tomcat 4.0?

Nix.

Attachment