Skip site navigation (1) Skip section navigation (2)

Peripheral Links

Header And Logo

PostgreSQL
| The world's most advanced open source database.

Site Navigation

Search archives
  Advanced Search

Re: path and classpath settings


  • From: Lew <noone(at)lwsc(dot)ehost-services(dot)com>
  • To: pgsql-jdbc(at)postgresql(dot)org
  • Subject: Re: path and classpath settings
  • Date: Sat, 27 Feb 2010 20:35:30 -0500
  • Message-id: <hmch90$91v$1@news.albasani.net> <text/plain>

shilpa r wrote:
am working on postgreSQL
i [sic] wanted to know the path and CLASSPATH settings on the environbment variable of Xp

For JDBC, the PATH environment variable ("envar") is not relevant. While you can include the PostgreSQL JDBC JAR file in the CLASSPATH, for most purposes that is too much. The CLASSPATH envar affects every Java program that doesn't override it, including in your case any that do not really need the Postgres JDBC JAR.

Much better would be to use the "-classpath" or equivalent "-cp" option to the "java" command line, or the equivalent if you are using an application server like Tomcat or Glassfish. You should read up on the document for how to set the classpath for a program within your environment, e.g., through the tutorials and other documentation at java.sun.com.

as am stuck up with an error stating ClassNotFoundException
when am trying to connect to Database thru an java [sic] code

Do you have the JDBC JAR on your system?  If not, it's available from
<http://jdbc.postgresql.org/>

After that, it's a matter of including it in the classpath the same way you would any other library JAR:

ordinary command line: "-cp" as stated above

using "java -jar": in a directory relative to the application's JAR and specified by that main JAR's manifest. (Using "java -jar" the JVM ignores any CLASSPATH or "-classpath" specifications.)

Deploying to an application server: In the "WEB-INF/lib/" directory of the WAR or the equivalent for an EAR.

It is a powerful thing to know how to specify the classpath for a Java program.

--
Lew



Home | Main Index | Thread Index

Privacy Policy | About PostgreSQL
Copyright © 1996 – 2012 PostgreSQL Global Development Group