Re: Problem with connecting to postgres using JDBC with JSP, but not

From: Jens Carlberg <jenca(at)lysator(dot)liu(dot)se>
To: Peter Adamek <peter(dot)adamek(at)utoronto(dot)ca>
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: Problem with connecting to postgres using JDBC with JSP, but not
Date: 2001-12-27 09:20:13
Message-ID: 3C2AE7CD.E1E63000@lysator.liu.se
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

<snip>

> At this point, I followed Jens suggestion to modify my code to the
> following. In the following code, I don't run any SQL statements against
> the database, but after attempting to make the database connection, I check
> to see if it (the connection) is equal to null and sure enough it is. This
> is what was generating the above error. So at this point, I'm not sure of
> what to do to. I think my problem is in the way the drivers or classes are
> being initialized, but I'm not sure. I have folllowed the standard way to
> connect to the database as has been suggested in the books and on numerous
> sites, but nothing seems to work. I know the connection string works fine,
> becuase the same one works in my "HelloPostgreSQL.java" pure JAVA (non-JSP)
> program.

Since you don't get a Connection, the problem most likely is a CLASSPATH
problem, i.e. the JVM that runs Tomcat doesn't find the Postgresql
Driver class. I suggest you replace

/* Load the driver */
try {Class.forName("org.postgresql.Driver");}
catch (ClassNotFoundException e) {}

with

/* Load the driver */
try {new org.postgresql.Driver();}
catch (SQLException e) {}

This will have 2 effects:
1. You have to have the Postgresql jar in your CLASSPATH when you
compile (or have it in the JVMs ext-directory).
2. If the jar is missing in Tomcats JVMs CLASSPATH, you should get a
clear error in the log, stating it couldn't find the class
org.postgresql.Driver.

Hm, if I'm right in my guesses, the jar isn't in Tomcats CLASSPATH.
Perhaps you could save yourself some trouble by checking that out first.
Check this HOW-TO:

http://jakarta.apache.org/tomcat/tomcat-4.0-doc/class-loader-howto.html

<snip>

Yours,
///Jens Carlberg

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message Justin Clift 2001-12-27 11:42:45 Does the 7.2 JDBC driver work properly with DbVisualizer yet?
Previous Message Peter Adamek 2001-12-27 07:16:22 Problem with connecting to postgres using JDBC with JSP, but not JDBC with Java