getXXX(): Null Pointer Exception - Mailing list pgsql-jdbc

From Jean-Christian Imbeault
Subject getXXX(): Null Pointer Exception
Date
Msg-id 3DAD14EE.3040300@mega-bucks.co.jp
Whole thread Raw
List pgsql-jdbc
I'm a newbie so please forgive if this is a simple programming error,
but ...

I am getting an error while trying the simplest of queries to my DB. I
can't get the result back from the ResultSet, I keep getting
NullPointerExceptions every time I try any of the ResultSet.getXXX()
methods. But if check the MetaData of the ResultSet I see that it is
does contain one row ...

Can someone tell me what I am doing wrong or point me in the right
direction?

Here's part of my code and the output:

Code:
----------

    public String getNumberOfMembers() {
      int cols = 0;
      String count = "0";
      Object o;
      sql = "select count(id) from members";
      connect();
      try {
        res = stmt.executeQuery(sql);
        System.out.println("Ok query " + sql);
      }
      catch (Exception e) {
        System.out.println("Error executing query " + sql);
      }

      if (res == null) System.out.println("NULL");
      else System.out.println("NOT NULL");
      try {
        ResultSetMetaData dat  = res.getMetaData();
        cols = dat.getColumnCount();
      }
      catch (SQLException e) {
        System.out.println("Error getting MetaData");
      }
      System.out.println("Col count is " + cols);
      try {
        o = res.getObject("count");
      }
      catch (SQLException e) {
      }
      close();
      return count;
    }


Output:
----------
Ok query: select count(id) from members
NOT NULL
Col count is 1
java.lang.NullPointerException
          at org.postgresql.jdbc2.ResultSet.getObject(ResultSet.java:730)
          at org.postgresql.jdbc2.ResultSet.getObject(ResultSet.java:803)
          at TAL.MemberDB.getNumberOfMembers(MemberDB.java:40)
          at
TAL.MemberSearchPanel.jcInitComponents(MemberSearchPanel.java:64)
          at TAL.MemberSearchPanel.<init>(MemberSearchPanel.java:37)
          at TAL.Tabs.<init>(Tabs.java:11)
          at TAL.Main.main(Main.java:30)


pgsql-jdbc by date:

Previous
From: Curt Sampson
Date:
Subject: Re: [GENERAL] Prepared statement performance...
Next
From: Jean-Christian Imbeault
Date:
Subject: Re: getXXX(): Null Pointer Exception