Re: Connection Problem with JDBC - Mailing list pgsql-jdbc

From Barry Lind
Subject Re: Connection Problem with JDBC
Date
Msg-id 3C680340.2040407@xythos.com
Whole thread Raw
In response to Connection Problem with JDBC  ("Steven Murphy" <stevenmurphy@hotmail.com>)
Responses Re: Connection Problem with JDBC  ("Dave Cramer" <Dave@micro-automation.net>)
List pgsql-jdbc
Steven,

This works for me.

[blind@barry work]$ echo $CLASSPATH
.:/home/blind/work/wfs/jars/postgresjdbc.jar
[blind@barry work]$ java -Djdbc.drivers=org.postgresql.Driver
ConnectDemo jdbc:postgresql://localhost:5432/files blind ""
Connection successful.
Connection as String: org.postgresql.jdbc2.Connection@4ac268

I am running on RedHat 7.2, jdk 1.3.1_01 with the postgres 7.2 jdbc drivers.

Are you sure that the jdbc jar file is in your CLASSPATH, and that you
have exported the CLASSPATH setting back to the environment?

thanks,
--Barry



Steven Murphy wrote:
> Hi,
>
> I'm trying to connect to a PostgreSQL database using JDBC but when I run
> the program I get an error message saying "No suitable driver".
>
> I'm using PostgreSQL 7.1.3 and java 1.3.1_01.
>
> I have added the jdbc7.1-1.2.jar file to the CLASSPATH.
>
> The command I am using to run the program is
> java -Djdbc.drivers=org.postgresql.Driver ConnectDemo
> jdbc:postgresql:javatest postgres ' '
>
> The program I'm trying to use is :-
>
> import java.sql.*;
>
> public class ConnectDemo {
>
>  public static void main(String[] argv) {
>      // No need to register the driver, since the user
>      // used -Djdbc.drivers to set it.
>
>      // Check the arguments.
>      //
>      if (argv.length < 3) {
>          usage();
>      }
>      String url  = argv[0];
>      String user = argv[1];
>      String pass = argv[2];
>
>      // Invoke getConnection() to create the
>      // connection object.
>      //
>      Connection conn;
>      try {
>          conn = DriverManager.getConnection(url, user, pass);
>          System.out.println("Connection successful.");
>          System.out.println("Connection as String: " + conn);
>      } catch (SQLException e) {
>          System.err.println( e.getMessage() );
>          System.exit(-1);
>      }
>  }
>
>  static void usage() {
>      System.err.println("Usage:");
>      System.err.print("java -Djdbc.drivers=DRIVERCLASS PROGRAM ");
>      System.err.println("URL USER PASS");
>      System.exit(-1);
>
>  }
> }
>
> I would be greatful for any help as I trying to do this for my final
> year project at University and the deadline is fast approaching.
>
> Cheers
> Steven Murphy.
>
> _________________________________________________________________
> Send and receive Hotmail on your mobile device: http://mobile.msn.com
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/users-lounge/docs/faq.html
>



pgsql-jdbc by date:

Previous
From: David Siebert
Date:
Subject: null pointer
Next
From: David Siebert
Date:
Subject: Null pointer error using absolute