getXXX(): Null Pointer Exception

From: Jean-Christian Imbeault <jc(at)mega-bucks(dot)co(dot)jp>
To: pgsql-jdbc <pgsql-jdbc(at)postgresql(dot)org>
Subject: getXXX(): Null Pointer Exception
Date: 2002-10-16 07:27:42
Message-ID: 3DAD14EE.3040300@mega-bucks.co.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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)

Browse pgsql-jdbc by date

  From Date Subject
Next Message Jean-Christian Imbeault 2002-10-16 07:36:11 Re: getXXX(): Null Pointer Exception
Previous Message Curt Sampson 2002-10-16 06:06:30 Re: [JDBC] Prepared statement performance...