Diagnosing your problem is a little more difficult because you are trapping
any exceptions. It would help narrow the possible causes if you would put a
"ex.printStackTrace();" in the catch clause. That said, here are a couple
possibilities:
1) Is the postgresql.jar in your CLASSPATH?
2) Have you configured $PGDATA/pg_hba.conf to allow connections from your
client machine? You would need a line similar to:
host midterm 123.456.789.01 255.255.255.0 trust
^^^^^^^^^^^^^^
IP of client machine here
3)Are you sure user "bryon" is a valid Postgres user? You would have had to
either install Postgres as "bryon", or have run the "createuser" script.
Hope some of this helps.
Phil Culberson
DAT Services
-----Original Message-----
From: gauss [mailto:carlga@mail.ohusc.k12.in.us]
Sent: Tuesday, April 11, 2000 5:37 AM
To: pgsql-general@postgresql.org
Subject: [GENERAL] JDBC connection - DB Prep?
I have a PGSQL 6.5.2 running on redhat linux and am trying to connect to it
from a remote machine. I have the DB and table created and can access the
table at the console ("pgsql midterm" midterm=>).
when I run SimpleExample.class the first three println statments display.
The fourth does not. I think I have my code right. How do I verify that
Postgresql is accepting connections. I can "ping" the machine that
Posgresql is on.
I know that postmaster needs to be started with the -i. How do I verify
this with the default installation of PGSQL when Linux is installed. What
else do I need to do to prepare the database for connection through JDBC?
Here is my Java code:
import java.sql.*;
class SimpleExample{
public static void main(String[] args) {
System.out.println("before the try");
try
{
String url =
"jdbc:postgresql://172.20.50.25/midterm";
System.out.println("before the Class.forName
statement");
Class.forName("postgresql.Driver");
System.out.println("before the Connection
statement");
Connection myConnection =
DriverManager.getConnection(url, "bryon", "1234");
System.out.println("Connection is open");
if (!myConnection.isClosed())
{myConnection.close();}
}
catch (java.lang.Exception ex){}
}
}
Thanks for the help.
Bryon