Re: Urgent : JDBC problem in PostgreSql for Linux

Поиск
Список
Период
Сортировка
От Fernando Nasser
Тема Re: Urgent : JDBC problem in PostgreSql for Linux
Дата
Msg-id 3EF4E5D9.5040703@redhat.com
обсуждение исходный текст
Ответ на Urgent : JDBC problem in PostgreSql for Linux  ("Kallol Nandi" <kallol.nandi@indussoft.com>)
Ответы Re: Urgent : JDBC problem in PostgreSql for Linux  ("Kallol Nandi" <kallol.nandi@indussoft.com>)
Список pgsql-jdbc
Hi Kallol,

You may have set your JAVA_HOME variable to point to the Sun Java 1.4.1
but you forgot to add the Java bin directory to the front of your PATH.
  As a result you are getting the GNU java instead.

Try

which java

When you get something like:
/usr/java/j2sdk1.4.1_02/bin/javac

things will go much better.

Good luck,
Fernando


Kallol Nandi wrote:
> 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.postgresql.Driver@8071ea0 <mailto: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.
>
> *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.postgresql.Driver@8071ea0
> <mailto:org.postgresql.Driver@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.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 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."
>


--
Fernando Nasser
Red Hat Canada Ltd.                     E-Mail:  fnasser@redhat.com
2323 Yonge Street, Suite #300
Toronto, Ontario   M4P 2C9


В списке pgsql-jdbc по дате отправления:

Предыдущее
От: "Rodrigo F. Baroni"
Дата:
Сообщение: Re: Urgent : JDBC problem in PostgreSql for Linux
Следующее
От: Thomas Kellerer
Дата:
Сообщение: Re: Urgent : JDBC problem in PostgreSql for Linux