> I am trying to use servlet to access postgreSQL
> database but I am not able to. I am able to run
> servlets just fine as long as they don't try to access
> postgreSQL database.  If I run stand alone Java
> program, then I am able to access postgreSQL database
> just fine.  I use: export
> CLASSPATH=/usr/local/jakarta-tomcat-4.0/common/lib/jdbc7.1-1.2.jar:${CLASSPATH}
> to install the driver.  I am using RedHat 7.2, and
> have installed all the postgreSQL RPMs that came with
> the CD.  Please can somebody help me as to what I am
> doing wrong.  Do I have to edit some XML file?

In order to connect to a PostgreSQL database from Tomcat 4.01, you need to:

- place JDBC driver in a directory where Tomcat's classloader would pick it up
- load the driver
- connect to DB

The directory for JDBC driver placement can be:

- $CATALINA_HOME/common/lib (this will make PostgreSQL JDBC available to both Tomcat 
and all WebApps)
- $WEB_APP/WEB-INF/lib (this will make PostgreSQL JDBC available to just that WebApp)

To load the driver, you have to do this at least once (preferably from a "load on 
startup" servlet):

Class.forName( "org.postgresql.Driver" );

Connecting is standard.

Nix.


Reply via email to