Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-28-2009, 10:40 AM
jon80's Avatar
Senior Member
 
Join Date: Feb 2008
Posts: 195
Rep Power: 2
jon80 is on a distinguished road
Default [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?

Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 06-28-2009, 11:01 AM
Senior Member
 
Join Date: Feb 2009
Posts: 589
Rep Power: 1
pbrockway2 is on a distinguished road
Default
Quote:
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:

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

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 11:06 AM.
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Another newbie PhHein Introductions 0 04-22-2009 02:26 PM
I am newbie Seoplanner Introductions 0 11-11-2008 02:22 PM
How to use JDBC Template classes to control basic JDBC processing and error handling Java Tip Java Tips 0 04-01-2008 11:17 AM
Newbie CSnoob87 Introductions 2 02-18-2008 09:49 AM
How to use JDBC Template classes to control basic JDBC processing and error handling JavaBean Java Tips 0 09-28-2007 01:56 PM


All times are GMT +2. The time now is 06:06 PM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org