Обсуждение: Getting connected

Поиск
Список
Период
Сортировка

Getting connected

От
"Peter Cook"
Дата:
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


Re: Getting connected

От
Oliver Jowett
Дата:
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