Re: Connection Problem with JDBC

From: "Dave Cramer" <Dave(at)micro-automation(dot)net>
To: "'Steven Murphy'" <stevenmurphy(at)hotmail(dot)com>, <pgsql-jdbc(at)postgresql(dot)org>
Subject: Re: Connection Problem with JDBC
Date: 2002-02-11 16:20:14
Message-ID: 006801c1b317$fcb5b0f0$8201a8c0@inspiron
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Steven,

Well, you've got me beat. I just tried your code and it works as
advertised in Jbuilder, but from the command line it doesn't load the
driver?

If I were you, I would just load the driver in your main.

Dave

-----Original Message-----
From: pgsql-jdbc-owner(at)postgresql(dot)org
[mailto:pgsql-jdbc-owner(at)postgresql(dot)org] On Behalf Of Steven Murphy
Sent: Monday, February 11, 2002 10:09 AM
To: pgsql-jdbc(at)postgresql(dot)org
Subject: [JDBC] Connection Problem with JDBC

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

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message Glenn Holmer 2002-02-11 16:28:01 Re: BigDecimal
Previous Message Sean Alphonse 2002-02-11 15:41:52 Connection Pooling.