Results 1 to 2 of 2
Thread: [newbie] Postgre jdbc
- 06-28-2009, 09:40 AM #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:
- 06-28-2009, 10:01 AM #2
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,547
- Rep Power
- 11
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.I've noted that the machine on which java is installed does not have any value for the environment variable 'CLASSPATH'.
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:
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.)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
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
-cp and -classpath are synonymous. Mind the dot.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
Last edited by pbrockway2; 06-28-2009 at 10:06 AM.
Similar Threads
-
Another newbie
By PhHein in forum IntroductionsReplies: 0Last Post: 04-22-2009, 01:26 PM -
I am newbie
By Seoplanner in forum IntroductionsReplies: 0Last Post: 11-11-2008, 01:22 PM -
How to use JDBC Template classes to control basic JDBC processing and error handling
By Java Tip in forum Java TipReplies: 0Last Post: 04-01-2008, 10:17 AM -
Newbie
By CSnoob87 in forum IntroductionsReplies: 2Last Post: 02-18-2008, 08:49 AM -
How to use JDBC Template classes to control basic JDBC processing and error handling
By JavaBean in forum Java TipReplies: 0Last Post: 09-28-2007, 12:56 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks