1. ## [newbie] Postgre jdbc

I'm trying to "drop" postgresql-8.3-604.jdbc4.jar within the CLASSPATH, so that I can use it to connect to my postgre database.

I've noted that the machine on which java is installed does not have any value for the environment variable 'CLASSPATH'.

Any idea where to drop it?

:confused:

2. Moderator
Join Date
Feb 2009
Location
New Zealand
Posts
4,565
Rep Power
12
I've noted that the machine on which java is installed does not have any value for the environment variable 'CLASSPATH'.
The classpath (the list of locations from where the java tools will locate classes and resources) and the operating system CLASSPATH environment variable are related, but different, things. The tools will use the environment variable to determine the classpath they use but only if there is no classpath specified as part of the command used to run them.

Usually you would specify the classpath as part of the command used to launch the java tool and would not rely on the existence or particular value of CLASSPATH.

You can use the -cp switch for this.

So if you were compiling from the directory containing the source you could use:

Java Code:
javac -cp .:/path/to/postgresql-8.3-604.jdbc4.jar mypackage/MyApp.java
java -cp .:/path/to/postgresql-8.3-604.jdbc4.jar mypackage.MyApp
As suggested by that example the postgresql jar can be put anywhere you like. Mentioning it as part of the command to compile or run makes it part of the classpath. (And, incidently, that's what you usually want: you want the jar to become part of the classpath not to be located somewhere on the classpath.)

If you haven't done so, read the fine manual which in this case includes an informative discussion of How Classes Are Found.

EDIT:

A Windows translation of the commands might be

Java Code:
javac -cp .;\path\to\postgresql-8.3-604.jdbc4.jar mypackage\MyApp.java
java -cp .;\path\to\postgresql-8.3-604.jdbc4.jar mypackage.MyApp
-cp and -classpath are synonymous. Mind the dot.
Last edited by pbrockway2; 06-28-2009 at 10:06 AM.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•