Problem with connecting with Postgresql using JDBC

From: jo raj <joeinvitesu(at)yahoo(dot)co(dot)in>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: Problem with connecting with Postgresql using JDBC
Date: 2004-02-18 12:29:43
Message-ID: 20040218122943.44260.qmail@web8303.mail.in.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Hai everybody,

I am a newbie to PostgreSQL and I am a student
doing a project based on Postgresql for my completion
of my studies. I can't get to my carefully set-up
database through java with a program. I think I've hit
most of the required set-up points. I've got all the
postgresql packages installed (checked with rpm -qa |
grep -i postgres; they're there, including the jdbc
one). I set tcpip_socket = true in
/var/lib/pgsql/data/postgresql.conf. I also updated
/etc/rc.d/init.d/. When executing the "pg_ctl -D
/var/lib/pgsql/data status" the output was

pg_ctl: postmaster is running (pid: 7245)
Command line was:
/usr/bin/postmaster '-p' '5432'

I have the right driver in the classpath (I passed in

export
CLASSPATH=$CLASSPATH:/usr/share/pgsql/pg73b1jdbc3.jar
when compiling and running).

I added the lines "host all 127.0.0.1 255.255.255.255
trust" /var/lib/pgsql/data/pg_hba.conf
I created a new database, "skylab"
I added the user "root" with the password "redhat" to
the
database, and verified by logging into psql with -U
xxx (had pg_hba.conf set to password so was
challenged and succeeded) With all of this, my java
program has these lines:
import java.sql.*;
public class jdbc{
public static void main(String args[]){
String url =
"jdbc:postgresql://redhat:5432/skylab";
Connection con=null;
//String tab = " " ;
Statement stmt ;
String query1 = "select * from netprint" ;



try
{
//here we load jdbc driver
Class.forName("org.postgresql.Driver");



}



catch(java.lang.ClassNotFoundException e)
{
System.out.println("ClassNotFoundException: "
+ e.getMessage());
}
System.out.println("Got class.forName");
try {
//here iam connecting to my database
System.out.println("Trying for connection A" );

DriverManager.setLogStream(System.out);
System.out.println("Trying for connection B" );
con = DriverManager.getConnection(url, "root",
"redhat");
System.out.println("Didn't fault on connection.");
stmt = con.createStatement() ;
ResultSet rs ;
stmt.executeUpdate("insert into netprint values('bosc'
,'redhat1','lp2','10.21.31.21','2004/02/09','16:00:05'
)");
rs = stmt.executeQuery(query1) ;
con.close();
}
catch (SQLException ex) {
System.err.println("SQLException: " +
ex.getMessage()) ;
ex.printStackTrace();
}



}


I get the error Got class.forName
Trying for connection A
Trying for connection B
SQLException: Driver not found for URL:
jdbc:postgresql://redhat:5432/skylab
java.sql.SQLException: Driver not found for URL:
jdbc:postgresql://redhat:5432/skylab
at 0x40268e17:
java.lang.Throwable.Throwable(java.lang.String)
(/usr/lib/./libgcj.so.3)
at 0x4025bcd2:
java.lang.Exception.Exception(java.lang.String)
(/usr/lib/./libgcj.so.3)
at 0x402fce64:
java.sql.SQLException.SQLException(java.lang.String,
java.lang.String, int) (/usr/lib/./libgcj.so.3)
at 0x402fce14:
java.sql.SQLException.SQLException(java.lang.String)
(/usr/lib/./libgcj.so.3)
at 0x402fccd2:
java.sql.DriverManager.getConnection(java.lang.String,
java.util.Properties) (/usr/lib/./libgcj.so.3)
at 0x402fcc0e:
java.sql.DriverManager.getConnection(java.lang.String,
java.lang.String, java.lang.String)
(/usr/lib/./libgcj.so.3)
at 0x403831e7: ffi_call_SYSV
(/usr/lib/./libgcj.so.3)
at 0x403831a7: ffi_raw_call
(/usr/lib/./libgcj.so.3)
at 0x402306e8:
_Jv_InterpMethod.continue1(_Jv_InterpMethodInvocation)
(/usr/lib/./libgcj.so.3)
at 0x40230ff4: _Jv_InterpMethod.run(ffi_cif, void,
ffi_raw, _Jv_InterpMethodInvocation)
(/usr/lib/./libgcj.so.3)
at 0x4022e504: _Jv_InterpMethod.run_normal(ffi_cif,
void, ffi_raw, void) (/usr/lib/./libgcj.so.3)
at 0x4038305c: ?? (??:0)
at 0x40242dd8:
gnu.gcj.runtime.FirstThread.call_main()
(/usr/lib/./libgcj.so.3)
at 0x402ad02d: gnu.gcj.runtime.FirstThread.run()
(/usr/lib/./libgcj.so.3)
at 0x4024fc4c: _Jv_ThreadRun(java.lang.Thread)
(/usr/lib/./libgcj.so.3)
at 0x4021c8ac: _Jv_RunMain(java.lang.Class, byte
const, int, byte const, boolean)
(/usr/lib/./libgcj.so.3)
at 0x08048910: ?? (??:0)
at 0x42015574: __libc_start_main
(/lib/tls/libc.so.6)
at 0x080486c1: ?? (??:0)
(Note it's finding the driver with the forName()
method call).I've tried using
jdbc:postgresql://redhat:5432/skylab.Any suggestion
you have would be extremely useful for my completion
of the project.

=====

Bye from JOE

________________________________________________________________________
Yahoo! India Insurance Special: Be informed on the best policies, services, tools and more.
Go to: http://in.insurance.yahoo.com/licspecial/index.html

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Jan de Visser 2004-02-18 13:41:19 Re: Problem with connecting with Postgresql using JDBC
Previous Message Chris Smith 2004-02-17 22:52:36 Re: isSingleXXX in AbstractJdbc1Statement