javasqlpostgresqljdbcdebian

PostgreSQL - Installing JDBC driver


I'm having a hard time working out how I should be installing the JDBC driver for PostgreSQL on my debian 6.0 server. I have moved the driver .jar into the following directory:

/usr/local/pgsql/share/java/postgresql.jar. 

Then the tutorials talk about using this code:

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

However, since I am new to postgreSQL I have no idea where I should be putting this line, or if this is even correct.

My question is, short of moving the jar file to this location, what do I actually need to do in order to install the JDBC driver on my postgreSQL installation?


EDIT: This is my setup:

Server 1: Tomcat + SOLR

Server 2: PostgreSQL with JDBC driver

SOLR on server 1 queries postgreSQL on server 2 via the JDBC driver


Solution

  • It is best to install your PostgreSQL driver into tomcat\lib folder. Just copy the driver jar to PATH_TO_TOMCAT\lib

    It is not a good idea to add things to the system CLASSPATH because you can end in class loader hell. Here is an example of how you end up in jar / classpath hell.

    See http://tomcat.apache.org/tomcat-7.0-doc/jndi-datasource-examples-howto.html