Skip site navigation (1) Skip section navigation (2)

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: (view raw or whole 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

when compiling and running).
 I added the lines "host all
 trust" /var/lib/pgsql/data/pg_hba.conf
 I created a new database, "skylab"
 I added the user "root" with the password "redhat" to
 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 =
    Connection con=null;
     //String tab = " " ;
  Statement stmt ;
      String query1 = "select * from netprint" ;
        //here we load jdbc 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" );
System.out.println("Trying for connection B" );
 con = DriverManager.getConnection(url, "root",
System.out.println("Didn't fault on connection.");
        stmt = con.createStatement() ;
        ResultSet rs ;
stmt.executeUpdate("insert into netprint values('bosc'
rs = stmt.executeQuery(query1) ;
     catch (SQLException ex) {
         System.err.println("SQLException: " +
ex.getMessage()) ;

I get the error Got class.forName
Trying for connection A
Trying for connection B
SQLException: Driver not found for URL:
java.sql.SQLException: Driver not found for URL:
   at 0x40268e17:
   at 0x4025bcd2:
   at 0x402fce64:
java.lang.String, int) (/usr/lib/./
   at 0x402fce14:
   at 0x402fccd2:
java.util.Properties) (/usr/lib/./
   at 0x402fcc0e:
java.lang.String, java.lang.String)
   at 0x403831e7: ffi_call_SYSV
   at 0x403831a7: ffi_raw_call
   at 0x402306e8:
   at 0x40230ff4:, void,
ffi_raw, _Jv_InterpMethodInvocation)
   at 0x4022e504: _Jv_InterpMethod.run_normal(ffi_cif,
void, ffi_raw, void) (/usr/lib/./
   at 0x4038305c: ?? (??:0)
   at 0x40242dd8:
   at 0x402ad02d:
   at 0x4024fc4c: _Jv_ThreadRun(java.lang.Thread)
   at 0x4021c8ac: _Jv_RunMain(java.lang.Class, byte
const, int, byte const, boolean)
   at 0x08048910: ?? (??:0)
   at 0x42015574: __libc_start_main
   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:


pgsql-jdbc by date

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

Privacy Policy | About PostgreSQL
Copyright © 1996-2015 The PostgreSQL Global Development Group