Re: Problem with connecting to postgres using JDBC with JSP, but not - Mailing list pgsql-jdbc

From Jens Carlberg
Subject Re: Problem with connecting to postgres using JDBC with JSP, but not
Date
Msg-id 3C2AE7CD.E1E63000@lysator.liu.se
Whole thread Raw
In response to Problem with connecting to postgres using jdbc7.0-1.2.jar  (Peter Adamek <peter.adamek@utoronto.ca>)
List 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

pgsql-jdbc by date:

Previous
From: Peter Adamek
Date:
Subject: Problem with connecting to postgres using JDBC with JSP, but not JDBC with Java
Next
From: Justin Clift
Date:
Subject: Does the 7.2 JDBC driver work properly with DbVisualizer yet?