No suitable driver found for jdbc:postgresql [error]

Поиск
Список
Период
Сортировка
От Jonathan Camilleri
Тема No suitable driver found for jdbc:postgresql [error]
Дата
Msg-id CAG15NM2dRmyPSkYffG2F0j+S+pZSR+8w2+YE7vrJOq0dZa2dHA@mail.gmail.com
обсуждение исходный текст
Ответы Re: No suitable driver found for jdbc:postgresql [error]
Re: No suitable driver found for jdbc:postgresql [error]
Список pgsql-general
1. Upon logging to SQL shell the following is being displayed:
Server [localhost]:
Database [postgres]:
Port [5432]:
Username [postgres]:
psql (9.0.4)
WARNING: Console code page (437) differs from Windows code page (1252)
         8-bit characters might not work correctly. See psql reference
         page "Notes for Windows users" for details.
Type "help" for help.

Where do I find the mentioned article?

2. When running a test program, sourced from Core Java Volume 2 (7th Edition), the following error is being displayed:
java.sql.SQLException: No suitable driver found for jdbc:postgresql:COREJAVA;cre
ate=true
        at java.sql.DriverManager.getConnection(DriverManager.java:602)
        at java.sql.DriverManager.getConnection(DriverManager.java:185)
        at TestDB.getConnection(TestDB.java:82)
        at TestDB.runTest(TestDB.java:43)
        at TestDB.main(TestDB.java:20)

In order to enable JDK to connect to the library files, I copied over postgresql-8.4-702.jdbc3.jar, and, 
postgresql-8.4-702.jdbc4.jar to C:\Program Files\Java\jre6\lib\ext.

It was assumed that the file naming indicates type 3 and type 4 respectively, and, I was intending to use type 4, since it is more efficient to use a library that translates Java to the database language for Postgre:

postgresql-8.4-702.jdbc3.jar
  • A type 3 driver is a pure Java client library that uses a database-independent protocol to communicate database requests to a server component, which then translates the requests into a database-specific protocol. This can simplify deployment since the database-dependent code is located only on the server.

    postgresql-8.4-702.jdbc4.jar 

  • A type 4 driver is a pure Java library that translates JDBC requests directly to a database-specific protocol.

TestDB.java
/**
   @version 1.01 2004-09-24
   @author Cay Horstmann (all rights reserved)
*/

import java.sql.*;
import java.io.*;
import java.util.*;

/**
   This program tests that the database and the JDBC 
   driver are correctly configured.
*/
class TestDB
{  
   public static void main (String args[])
   {  
      try
      {  
         runTest();
      }
      catch (SQLException ex)
      {  
         while (ex != null)
         {  
            ex.printStackTrace();
            ex = ex.getNextException();
         }
      }
      catch (IOException ex)
      {  
         ex.printStackTrace();
      }
   }

   /**
      Runs a test by creating a table, adding a value, showing the table contents, and 
      removing the table.
   */
   public static void runTest()
      throws SQLException, IOException
   {
      Connection conn = getConnection();
      try
      {
         Statement stat = conn.createStatement();
         
         stat.execute("CREATE TABLE Greetings (Message CHAR(20))");
         stat.execute("INSERT INTO Greetings VALUES ('Hello, World!')");
         
         ResultSet result = stat.executeQuery("SELECT * FROM Greetings");
         result.next();
         System.out.println(result.getString(1));
         stat.execute("DROP TABLE Greetings");      
      }
      finally
      {
         conn.close();
      }
   }

   /**
      Gets a connection from the properties specified
      in the file database.properties
      @return the database connection
   */
   public static Connection getConnection()
      throws SQLException, IOException
   {  
      Properties props = new Properties();
      FileInputStream in = new FileInputStream("database.properties");
      props.load(in);
      in.close();

      String drivers = props.getProperty("jdbc.drivers");
      if (drivers != null)
         System.setProperty("jdbc.drivers", drivers);
      String url = props.getProperty("jdbc.url");
      String username = props.getProperty("jdbc.username");
      String password = props.getProperty("jdbc.password");

      return DriverManager.getConnection(url, username, password);
   }
}

database.properties
dbc.drivers=org.postgresql.Driver
jdbc.url=jdbc:postgresql:COREJAVA;create=true
jdbc.username=postgre
jdbc.password=

command line
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\Jon>echo %CLASSPATH%
.;.;C:\PROGRA~1\JMF21~1.1E\lib\sound.jar;C:\PROGRA~1\JMF21~1.1E\lib\jmf.jar;C:\P
ROGRA~1\JMF21~1.1E\lib;C:\Program Files\Java\external_jars\junit4.9b2\junit4.9b2
\junit-4.9b2.jar;C:\Program Files\PostgreSQL\pgJDBC;

C:\Documents and Settings\Jon>cd c:\Program Files\PostgreSQL\pgJDBC

C:\Program Files\PostgreSQL\pgJDBC>dir
 Volume in drive C has no label.
 Volume Serial Number is D80F-8634

 Directory of C:\Program Files\PostgreSQL\pgJDBC

09/07/2011  15:42    <DIR>          .
09/07/2011  15:42    <DIR>          ..
03/04/2011  23:22           502,118 postgresql-8.4-702.jdbc3.jar
03/04/2011  23:22           539,510 postgresql-8.4-702.jdbc4.jar
09/07/2011  15:42    <DIR>          scripts
09/07/2011  15:42         5,759,102 uninstall-pgjdbc.exe
               3 File(s)      6,800,730 bytes
               3 Dir(s)  37,139,398,656 bytes free

C:\Program Files\PostgreSQL\pgJDBC>




How can I get the program running?


--
Jonathan Camilleri

Mobile (MT): 00356 7982 7113
E-mail: camilleri.jon@gmail.com
Please consider your environmental responsibility before printing this e-mail.
 
I usually reply to e-mails within 2 business days.  If it's urgent, give me a call.

В списке pgsql-general по дате отправления:

Предыдущее
От: Jeff Davis
Дата:
Сообщение: Re: [HACKERS] Creating temp tables inside read only transactions
Следующее
От: stefanu
Дата:
Сообщение: Hot standby on Windows