pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Getting connected
2+ messages / 2 participants
[nested] [flat]

* Getting connected
@ 2005-10-06 05:06 Peter Cook <ttpcook@hotmail.com>
  2005-10-06 22:02 ` Re: Getting connected Oliver Jowett <oliver@opencloud.com>
  0 siblings, 1 reply; 2+ messages in thread

From: Peter Cook @ 2005-10-06 05:06 UTC (permalink / raw)
  To: pgsql-jdbc

I have a Java Application running on Windows 2000.

Initially it accessed an Access database, and now that I have installed 
postgreSQL, I want to configure it to access postgreSQL.

Is there a single document that can take me through the steps, or can 
someone give me a simple checklist of what I need to do?????

I have downloaded the JDBC driver and I know:
- the driver class exists at "C:\Program Files\PostgreSQL\8.0\jdbc";
- it is in a JAR file ( I unpacked the JAR file, only to realise I didn't 
need to )

However my code throws a ClassNotFound exception.
Below is some code I wrote to test and set property values, and to check 
whether the driver directory and driver.class exist.

public void displayClasspath()
{
   String driverPath = "C:\\Program Files\\PostgreSQL\\8.0\\jdbc";
   String classpath = System.getProperty("java.class.path");
   _displayTextArea.append("Classpath = " + classpath + "\n");

   classpath = classpath + ";" + driverPath;
   System.setProperty("java.class.path", classpath);
   _displayTextArea.append("Classpath = " + classpath + "\n");

   System.setProperty("jdbc.drivers", driverPath);
   String drivers = System.getProperty("jdbc.drivers");
   _displayTextArea.append("Drivers = " + drivers + "\n");

   try
   {
      File driverDir = new File(driverPath);
      if ( driverDir.isDirectory() )
         _displayTextArea.append("DriverDir is a directory \n");
      else
        _displayTextArea.append("DriverDir is NOT a directory \n");

      File dFile = new File(driverPath + "\\org\\postgresql\\Driver.class");
      if ( dFile.isFile() )
         _displayTextArea.append("Driver is a file \n");
      else
         _displayTextArea.append("Driver is NOT a file \n");

      String driver = "org.postgresql.Driver";
      driverPath = driverPath + "\\" + driver;

      Class.forName(driverPath);
   }
   catch (ClassNotFoundException cnfe)
   {
     System.out.println("ClassNotFoundException.");
   }
}

This code produces these messages:
Classpath = C:\Eclipse\Workspace\Test
Classpath = C:\Eclipse\Workspace\Test;C:\Program Files\PostgreSQL\8.0\jdbc
Drivers = C:\Program Files\PostgreSQL\8.0\jdbc
DriverDir is a directory
Driver is a file

Yet whether I use:
Class.forName(driverPath)
OR
Class.forName(driver)
it throws a ClassNotFoundException


I believe the Postmaster needs to be started with a “-I” option to enable 
TCP/IP communication between application and server.
However it appears that the Postmaster is started in the boot sequence 
somewhere, and I don’t know where I need to make this adjustment.

I would appreciate your help.

Yours sincerely

Peter Cook

_________________________________________________________________
Sell your car for $9 on carpoint.com.au   
http://www.carpoint.com.au/sellyourcar




^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: Getting connected
  2005-10-06 05:06 Getting connected Peter Cook <ttpcook@hotmail.com>
@ 2005-10-06 22:02 ` Oliver Jowett <oliver@opencloud.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Oliver Jowett @ 2005-10-06 22:02 UTC (permalink / raw)
  To: Peter Cook <ttpcook@hotmail.com>; +Cc: pgsql-jdbc

Peter Cook wrote:

>   classpath = classpath + ";" + driverPath;
>   System.setProperty("java.class.path", classpath);

I don't think this works; the system classloader has already been set up
by this point so any change to the java.class.path property is likely to
be ignored.

If you want to modify the system classpath to include the driver jar,
you'll have to do that by passing an appropriate -classpath (or
CLASSPATH) setting to the JVM when you start it.

-O



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2005-10-06 22:02 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-10-06 05:06 Getting connected Peter Cook <ttpcook@hotmail.com>
2005-10-06 22:02 ` Oliver Jowett <oliver@opencloud.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox