Results 1 to 2 of 2
  1. #1
    jon80's Avatar
    jon80 is offline Senior Member
    Join Date
    Feb 2008
    Location
    Malta (EU)
    Posts
    211
    Rep Power
    7

    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?

    :confused:

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    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 11:06 AM.

Similar Threads

  1. Another newbie
    By PhHein in forum Introductions
    Replies: 0
    Last Post: 04-22-2009, 02:26 PM
  2. I am newbie
    By Seoplanner in forum Introductions
    Replies: 0
    Last Post: 11-11-2008, 02:22 PM
  3. Replies: 0
    Last Post: 04-01-2008, 11:17 AM
  4. Newbie
    By CSnoob87 in forum Introductions
    Replies: 2
    Last Post: 02-18-2008, 09:49 AM
  5. Replies: 0
    Last Post: 09-28-2007, 01:56 PM

Posting Permissions

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