NullPointerException with 7.2.1 ResultSet

From: Joseph Shraibman <jks(at)selectacast(dot)net>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: NullPointerException with 7.2.1 ResultSet
Date: 2002-04-25 20:25:48
Message-ID: 3CC8664C.1030202@selectacast.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Running the following code gives:
String 0 is blah
Exception in thread "main" java.lang.NullPointerException
at org.postgresql.jdbc2.ResultSet.next(ResultSet.java:113)
at PostgresTest.test1(PostgresTest.java:33)
at PostgresTest.main(PostgresTest.java:50)

Commenting out the executeUpdate() inside the for loop solves the problem. I think a
ResultSet that is closed should throw an IllegalStateException, not just let a
NullPointerException be thrown.

/**
* PostresTest.java
*
*
* Created: Thu Apr 25 15:51:47 2002
*
* @author <a href="mailto:jks(at)selectacast(dot)net">Joseph Shraibman</a>
* @version
*/

import java.sql.*;

public class PostgresTest{

private static void test1(String usr, String pwd) throws SQLException,
ClassNotFoundException{
int fetch_size = 50;

Class.forName("org.postgresql.Driver");
Connection db = DriverManager.getConnection("jdbc:postgresql:playpen", usr, pwd);
Statement st = db.createStatement();
st.executeUpdate("BEGIN;");
st.executeUpdate("CREATE table ptest1 (a int, b text);");
try{
st.executeUpdate("INSERT into ptest1 VALUES(1, 'blah');");
st.executeUpdate("DECLARE cname CURSOR FOR SELECT b FROM ptest1 GROUP BY b");
st.executeUpdate("CREATE TEMP TABLE tqt (id int, bstr text);");
while(true){
ResultSet rs = st.executeQuery("FETCH "+fetch_size+" FROM cname;");
int i = 0;
for ( ; rs.next() ; i++ ) {
String b = rs.getString(1);
System.out.println("String "+i+" is "+b);
st.executeUpdate("INSERT INTO tqt SELECT a FROM ptest1 where b =
'"+b+"';");
//st.executeUpdate("DELETE from tqt WHERE bstr = '"+b+"';");
}
if (i < fetch_size)
break;
}
st.executeUpdate("END;");
st.executeUpdate("DROP TABLE tqt;");
}finally{
st.executeUpdate("DROP table ptest1;");
st.executeUpdate("ABORT;");
}
}
public static void main(String[] args)throws Exception{
test1(args[0], args[1]);
}
} // PostresTest

Browse pgsql-jdbc by date

  From Date Subject
Next Message Erik Behrends 2002-04-26 12:12:10 Problems with "order by clause"
Previous Message tony 2002-04-25 10:58:14 preparedStatement