Обсуждение: JDBC in PostgreSql for Linux

Поиск
Список
Период
Сортировка

JDBC in PostgreSql for Linux

От
"Kallol Nandi"
Дата:
I am running a Java application on Linux which connects to the Postgresql on Linux using jdbcodbc bridge.
But this is the error I am getting :
 
sun.jdbc.odbc.JdbcOdbcDriver
java.lang.ClassNotFoundException: sun.jdbc.odbc.JdbcOdbcDriver
   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 0x402737a8: java.lang.ClassNotFoundException.ClassNotFoundException(java.lang.String) (/usr/lib/libgcj.so.3)
   at 0x4030b2be: java.net.URLClassLoader.findClass(java.lang.String) (/usr/lib/libgcj.so.3)
   at 0x402606d7: gnu.gcj.runtime.VMClassLoader.findClass(java.lang.String) (/usr/lib/libgcj.so.3)
   at 0x40272cc7: java.lang.ClassLoader.loadClass(java.lang.String, boolean) (/usr/lib/libgcj.so.3)
   at 0x40260e09: _Jv_FindClass(_Jv_Utf8Const, java.lang.ClassLoader) (/usr/lib/libgcj.so.3)
   at 0x4025d1fd: java.lang.Class.forName(java.lang.String, boolean, java.lang.ClassLoader) (/usr/lib/libgcj.so.3)
   at 0x4025d2bf: java.lang.Class.forName(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)
 
I have also tried running a Java application using the Native JDBC Driver.
I get the following error :
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)
 
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.Nandi@indussoft.com <http://uk.f200.mail.yahoo.com/ym/Compose?To=Kallol.Nandi@indussoft.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
elseis unauthorized. If you are the addressee, the contents of this email are intended for your use only and it must
notbe 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
dealtwith, 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."

 

Re: JDBC in PostgreSql for Linux

От
Thomas Kellerer
Дата:
Kallol Nandi schrieb:
> I am running a Java application on Linux which connects to the Postgresql on Linux using jdbcodbc bridge.
> But this is the error I am getting :
>
> I have also tried running a Java application using the Native JDBC Driver.
> I get the following error :
> 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)
>
> Please do reply me asap.
>
I have no real experience with Linux but as far as I know the JdbcOdbc
bridge is only distributed with the JDK for windows.

I'd suggest you stick with the native JDBC driver.
The second error indicates an error with your classpath. Is there a
reason why you don't use the SUN JDK for development? Does the GNU
compiler support Class.forName() (which is the usual way of registering
the drive) in the meantime?

Without your code, it's really hard to tell where your error is.

Thomas


Re: JDBC in PostgreSql for Linux

От
"Kallol Nandi"
Дата:
Hi,

This is the code that I am using for native JDBC Driver to connect to
PostgreSql in Linux.
BTW the version of Postgres is 7.2.2 and the jar file is jdbc7.1-1.2.jar.

****************************************************************************
*********
import java.io.*;
import java.sql.*;
import java.util.Properties;
import java.util.Vector;
import org.postgresql.Driver;

public class JDBCConnection
 {
public static void main(String args[])
  {
System.out.println("Testing");
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");
     System.out.println("Successful 1 ! ");
     Connection con=DriverManager.getConnection(url,userid,password);
     Statement stmt = con.createStatement();
     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;
   }
 }
}




****************************************************************************
*********
I am getting the error mentioned i my earlier mail in the following line :

     Connection con=DriverManager.getConnection(url,userid,password);

The error is :
****************************************************************************
**
 I get the following error :
 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)
****************************************************************************
*********


Thanks and Regards,
Kallol.

-----Original Message-----
From: pgsql-general-owner@postgresql.org
[mailto:pgsql-general-owner@postgresql.org]On Behalf Of Thomas Kellerer
Sent: Friday, June 20, 2003 4:12 PM
To: pgsql-general@postgresql.org
Subject: Re: [GENERAL] JDBC in PostgreSql for Linux



Kallol Nandi schrieb:
> I am running a Java application on Linux which connects to the Postgresql
on Linux using jdbcodbc bridge.
> But this is the error I am getting :
>
> I have also tried running a Java application using the Native JDBC Driver.
> I get the following error :
> 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)
>
> Please do reply me asap.
>
I have no real experience with Linux but as far as I know the JdbcOdbc
bridge is only distributed with the JDK for windows.

I'd suggest you stick with the native JDBC driver.
The second error indicates an error with your classpath. Is there a
reason why you don't use the SUN JDK for development? Does the GNU
compiler support Class.forName() (which is the usual way of registering
the drive) in the meantime?

Without your code, it's really hard to tell where your error is.

Thomas



---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster


Re: JDBC in PostgreSql for Linux

От
Thomas Kellerer
Дата:
Kallol Nandi schrieb:
> Hi,
>
> This is the code that I am using for native JDBC Driver to connect to
> PostgreSql in Linux.
> BTW the version of Postgres is 7.2.2 and the jar file is jdbc7.1-1.2.jar.
>
>
 > [...]
> ****************************************************************************
> I am getting the error mentioned i my earlier mail in the following line :
>
>      Connection con=DriverManager.getConnection(url,userid,password);
>
> The error is :
> ****************************************************************************
> **
>  I get the following error :
>  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

In 99% of the cases this is due to a badly defined classpath. I see two
potential problems here:

- You are not including the jdbc jar file when starting your app
- The GNU JVM does not support Class.forName("org.postgresql.Driver");

If you are sure you are defining the correct classpath: have you tried
the same thing with SUN's JDK??

Thomas


Re: JDBC in PostgreSql for Linux

От
Erik Price
Дата:

Kallol Nandi wrote:
> Hi,
>
> This is the code that I am using for native JDBC Driver to connect to
> PostgreSql in Linux.
> BTW the version of Postgres is 7.2.2 and the jar file is jdbc7.1-1.2.jar.

[...]

>      String server ="10.100.102.31";
>      String port ="5432";
>      String database="notes";
>      String url="jdbc:postgresql@"+server+":"+port+":"+database;

I don't know a lot about JDBC but I am using this URL with success:

jdbc:postgresql://localhost:5432/DATABASE_NAME_HERE

although I am using Sun 1.4 SDK.



Erik


Re: JDBC in PostgreSql for Linux

От
Dmitry Tkach
Дата:
You've got your url wrong - it should be "://" after postrgesql instead
of "@"

I hope, it helps...

Dima

Kallol Nandi wrote:

>Hi,
>
>This is the code that I am using for native JDBC Driver to connect to
>PostgreSql in Linux.
>BTW the version of Postgres is 7.2.2 and the jar file is jdbc7.1-1.2.jar.
>
>****************************************************************************
>*********
>import java.io.*;
>import java.sql.*;
>import java.util.Properties;
>import java.util.Vector;
>import org.postgresql.Driver;
>
>public class JDBCConnection
> {
>public static void main(String args[])
>  {
>System.out.println("Testing");
>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");
>     System.out.println("Successful 1 ! ");
>     Connection con=DriverManager.getConnection(url,userid,password);
>     Statement stmt = con.createStatement();
>     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;
>   }
> }
>}
>
>
>
>
>****************************************************************************
>*********
>I am getting the error mentioned i my earlier mail in the following line :
>
>     Connection con=DriverManager.getConnection(url,userid,password);
>
>The error is :
>****************************************************************************
>**
> I get the following error :
> 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)
>****************************************************************************
>*********
>
>
>Thanks and Regards,
>Kallol.
>
>-----Original Message-----
>From: pgsql-general-owner@postgresql.org
>[mailto:pgsql-general-owner@postgresql.org]On Behalf Of Thomas Kellerer
>Sent: Friday, June 20, 2003 4:12 PM
>To: pgsql-general@postgresql.org
>Subject: Re: [GENERAL] JDBC in PostgreSql for Linux
>
>
>
>Kallol Nandi schrieb:
>
>
>>I am running a Java application on Linux which connects to the Postgresql
>>
>>
>on Linux using jdbcodbc bridge.
>
>
>>But this is the error I am getting :
>>
>>I have also tried running a Java application using the Native JDBC Driver.
>>I get the following error :
>>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)
>>
>>Please do reply me asap.
>>
>>
>>
>I have no real experience with Linux but as far as I know the JdbcOdbc
>bridge is only distributed with the JDK for windows.
>
>I'd suggest you stick with the native JDBC driver.
>The second error indicates an error with your classpath. Is there a
>reason why you don't use the SUN JDK for development? Does the GNU
>compiler support Class.forName() (which is the usual way of registering
>the drive) in the meantime?
>
>Without your code, it's really hard to tell where your error is.
>
>Thomas
>
>
>
>---------------------------(end of broadcast)---------------------------
>TIP 4: Don't 'kill -9' the postmaster
>
>
>---------------------------(end of broadcast)---------------------------
>TIP 5: Have you checked our extensive FAQ?
>
>               http://www.postgresql.org/docs/faqs/FAQ.html
>
>



Re: JDBC in PostgreSql for Linux

От
"Kallol Nandi"
Дата:
I have changed the url to "jdbc:postgresql://"+server+":"+port+"/"+database


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;
   }
 }
}

but still the same problem.here is the error


Has Driver
org.postgresql.Driver@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.
But DriverManager.getDrivers() works fine and also returns the available
postgresql driver which I want.
I am not able to get the mistake.What might be the problem with the url?
Please do reply.It is urgent.

Thanks and Regards,
Kallol.




-----Original Message-----
From: Dmitry Tkach [mailto:dmitry@openratings.com]
Sent: Saturday, June 21, 2003 2:18 AM
To: Kallol Nandi
Cc: pgsql-general@postgresql.org
Subject: Re: [GENERAL] JDBC in PostgreSql for Linux


You've got your url wrong - it should be "://" after postrgesql instead
of "@"

I hope, it helps...

Dima

Kallol Nandi wrote:

>Hi,
>
>This is the code that I am using for native JDBC Driver to connect to
>PostgreSql in Linux.
>BTW the version of Postgres is 7.2.2 and the jar file is jdbc7.1-1.2.jar.
>
>***************************************************************************
*
>*********
>import java.io.*;
>import java.sql.*;
>import java.util.Properties;
>import java.util.Vector;
>import org.postgresql.Driver;
>
>public class JDBCConnection
> {
>public static void main(String args[])
>  {
>System.out.println("Testing");
>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");
>     System.out.println("Successful 1 ! ");
>     Connection con=DriverManager.getConnection(url,userid,password);
>     Statement stmt = con.createStatement();
>     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;
>   }
> }
>}
>
>
>
>
>***************************************************************************
*
>*********
>I am getting the error mentioned i my earlier mail in the following line :
>
>     Connection con=DriverManager.getConnection(url,userid,password);
>
>The error is :
>***************************************************************************
*
>**
> I get the following error :
> 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)
>***************************************************************************
*
>*********
>
>
>Thanks and Regards,
>Kallol.
>
>-----Original Message-----
>From: pgsql-general-owner@postgresql.org
>[mailto:pgsql-general-owner@postgresql.org]On Behalf Of Thomas Kellerer
>Sent: Friday, June 20, 2003 4:12 PM
>To: pgsql-general@postgresql.org
>Subject: Re: [GENERAL] JDBC in PostgreSql for Linux
>
>
>
>Kallol Nandi schrieb:
>
>
>>I am running a Java application on Linux which connects to the Postgresql
>>
>>
>on Linux using jdbcodbc bridge.
>
>
>>But this is the error I am getting :
>>
>>I have also tried running a Java application using the Native JDBC Driver.
>>I get the following error :
>>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)
>>
>>Please do reply me asap.
>>
>>
>>
>I have no real experience with Linux but as far as I know the JdbcOdbc
>bridge is only distributed with the JDK for windows.
>
>I'd suggest you stick with the native JDBC driver.
>The second error indicates an error with your classpath. Is there a
>reason why you don't use the SUN JDK for development? Does the GNU
>compiler support Class.forName() (which is the usual way of registering
>the drive) in the meantime?
>
>Without your code, it's really hard to tell where your error is.
>
>Thomas
>
>
>
>---------------------------(end of broadcast)---------------------------
>TIP 4: Don't 'kill -9' the postmaster
>
>
>---------------------------(end of broadcast)---------------------------
>TIP 5: Have you checked our extensive FAQ?
>
>               http://www.postgresql.org/docs/faqs/FAQ.html
>
>



Re: JDBC in PostgreSql for Linux

От
Thomas Kellerer
Дата:
Kallol Nandi schrieb:
> I am not able to get the mistake.What might be the problem with the url?
> Please do reply.It is urgent.
>
> Thanks and Regards,
> Kallol.
Did you try to use Sun's JDK?