Urgent : JDBC problem in PostgreSql for Linux

From: "Kallol Nandi" <kallol(dot)nandi(at)indussoft(dot)com>
To: <pgsql-jdbc(at)postgresql(dot)org>
Subject: Urgent : JDBC problem in PostgreSql for Linux
Date: 2003-06-21 12:21:29
Message-ID: NBEDKIHMDKLGDCDIJLMMEEEHCAAA.kallol.nandi@indussoft.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Hi All,

This is my first post to this mailing list.
I am facing an error in JDBC.
The linux version I am working on is 8.0, postgresql version is 7.2.2 and
the jar file I am using is postgresql.jar.

This is the code :

import java.sql.*;
import java.util.*;
import org.postgresql.Driver;

public class JDBCConnection
{
public static void main(String args[])
{
try
{
String server ="10.100.102.31";
String port ="5432";
String database="notes";
String url="jdbc:postgresql://"+server+":"+port+"/"+database;
String userid="postgres";
String password="postgres";
Class.forName("org.postgresql.Driver").newInstance();
//Driver d = (org.postgresql.Driver)(DriverManager.getDriver(url));
//DriverManager.registerDriver(d);
Enumeration enum = DriverManager.getDrivers();
while (enum.hasMoreElements())
{
System.out.println("Has Driver");
System.out.println(enum.nextElement().toString());
}

System.out.println("Successful 1 ! ");
java.sql.Connection
con=DriverManager.getConnection(url,userid,password);
java.sql.Statement stmt = con.createStatement();
java.sql.ResultSet rset = stmt.executeQuery ("Select count(*) as c from
testtable");
rset.next();
int currval = rset.getInt("c");

System.out.println("Successful 2 ! ");
System.out.println(currval);
con.close();
}
catch(Exception ex) {
System.out.println("Error problem!");
System.out.println(ex.getMessage());
ex.printStackTrace();
return;
}
}
}

Here is the error :

Has Driver
org(dot)postgresql(dot)Driver(at)8071ea0
Successful 1 !
Error problem!
Driver not found for URL: jdbc:postgresql://10.100.102.31:5432/notes
java.sql.SQLException: Driver not found for URL:
jdbc:postgresql://10.100.102.31:5432/notes
at 0x4028115f:
java.lang.Throwable.Throwable(java.lang.String)(/usr/lib/libgcj.so.3)
at 0x402740d2:
java.lang.Exception.Exception(java.lang.String)(/usr/lib/libgcj.so.3)
at 0x40316294:
java.sql.SQLException.SQLException(java.lang.String,java.lang.String, int)
(/usr/lib/libgcj.so.3)
at 0x40316244:
java.sql.SQLException.SQLException(java.lang.String)(/usr/lib/libgcj.so.3)
at 0x40316102:
java.sql.DriverManager.getConnection(java.lang.String,java.util.Properties)
(/usr/lib/libgcj.so.3)
at 0x4031603a:
java.sql.DriverManager.getConnection(java.lang.String,java.lang.String,
java.lang.String) (/usr/lib/libgcj.so.3)
at 0x4039d347: ffi_call_SYSV (/usr/lib/libgcj.so.3) at 0x4039d307:
ffi_raw_call (/usr/lib/libgcj.so.3)
at 0x40248528:
_Jv_InterpMethod.continue1(_Jv_InterpMethodInvocation)(/usr/lib/libgcj.so.3)
at 0x40248e34: _Jv_InterpMethod.run(ffi_cif, void,
ffi_raw,_Jv_InterpMethodInvocation) (/usr/lib/libgcj.so.3)
at 0x40246424: _Jv_InterpMethod.run_normal(ffi_cif, void, ffi_raw,
void)(/usr/lib/libgcj.so.3)
at 0x4039d1bc: ?? (??:0) at 0x4025b308:
gnu.gcj.runtime.FirstThread.call_main()(/usr/lib/libgcj.so.3)
at 0x402c60b1: gnu.gcj.runtime.FirstThread.run() (/usr/lib/libgcj.so.3)
at 0x40267fdc: _Jv_ThreadRun(java.lang.Thread) (/usr/lib/libgcj.so.3)
at 0x4023478c: _Jv_RunMain(java.lang.Class, byte const, int, byte
const,boolean) (/usr/lib/libgcj.so.3)
at 0x08048900: ?? (??:0)
at 0x420158d4: ?? (??:0)
at 0x080486c1: ?? (??:0)

If I uncomment the following lines
//Driver d = (org.postgresql.Driver)(DriverManager.getDriver(url));
//DriverManager.registerDriver(d);
and run the application I get null pointer exception as
DriverManager.getDriver(url) does not get a driver for the corresponding
Url.

This is the error :
Error problem!
null
java.lang.NullPointerException
at 0x4028112c: java.lang.Throwable.Throwable() (/usr/lib/libgcj.so.3)
at 0x402740af: java.lang.Exception.Exception() (/usr/lib/libgcj.so.3)
at 0x402779b3: java.lang.RuntimeException.RuntimeException()
(/usr/lib/libgcj.so.3)
at 0x402770a7: java.lang.NullPointerException.NullPointerException()
(/usr/lib/libgcj.so.3)
at 0x40233547: _Jv_ThrowNullPointerException (/usr/lib/libgcj.so.3)
at 0x40315eb4: java.sql.DriverManager.getDriver(java.lang.String)
(/usr/lib/libgcj.so.3)
at 0x4039d347: ffi_call_SYSV (/usr/lib/libgcj.so.3)
at 0x4039d307: ffi_raw_call (/usr/lib/libgcj.so.3)
at 0x40248528: _Jv_InterpMethod.continue1(_Jv_InterpMethodInvocation)
(/usr/lib/libgcj.so.3)
at 0x40248e34: _Jv_InterpMethod.run(ffi_cif, void, ffi_raw,
_Jv_InterpMethodInvocation) (/usr/lib/libgcj.so.3)
at 0x40246424: _Jv_InterpMethod.run_normal(ffi_cif, void, ffi_raw, void)
(/usr/lib/libgcj.so.3)
at 0x4039d1bc: ?? (??:0)
at 0x4025b308: gnu.gcj.runtime.FirstThread.call_main()
(/usr/lib/libgcj.so.3)
at 0x402c60b1: gnu.gcj.runtime.FirstThread.run() (/usr/lib/libgcj.so.3)
at 0x40267fdc: _Jv_ThreadRun(java.lang.Thread) (/usr/lib/libgcj.so.3)
at 0x4023478c: _Jv_RunMain(java.lang.Class, byte const, int, byte const,
boolean) (/usr/lib/libgcj.so.3)
at 0x08048900: ?? (??:0)
at 0x420158d4: ?? (??:0)
at 0x080486c1: ?? (??:0)

But DriverManager.getDrivers() works fine and also returns the available
postgresql driver which I want i.e. org(dot)postgresql(dot)Driver(at)8071ea0
Is there any problem with the url format that I am passing?
Please do reply me asap.

Thanks and Regards,
Kallol Nandi,
Systems Analyst,
Indus Software - A Division of R Systems International Ltd.,
Tidel Park, Taramani, Chennai-600113, India.
Phone: +91-44-22540014/6 Extn: 209
Fax: +91-44-22540017
Email: Kallol(dot)Nandi(at)indussoft(dot)com
Visit us @ http://www.indussoft.com/
"The information in this email is confidential, and intended solely for the
addressee. Access to this email by anyone else is unauthorized. If you are
the addressee, the contents of this email are intended for your use only and
it must not be forwarded to any third party, without first obtaining written
authorization from the originator, or Indus Software. It may contain
information, which is confidential and legally privileged, and the same
shall not be used, or dealt with, by any third party, in any manner
whatsoever, without the specific consent of Indus Software.

The opinions expressed are those of the sender, and do not necessarily
reflect those of the Indus Software."

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Thomas Kellerer 2003-06-21 12:38:33 Re: Urgent : JDBC problem in PostgreSql for Linux
Previous Message Didrik Pinte 2003-06-20 07:30:18 Re: Signed Applet : how ? (was: Connect Socket problem)