From: | Jeff Duffy <jeff(at)alanne(dot)com> |
---|---|
To: | <pgsql-jdbc(at)postgresql(dot)org> |
Subject: | NullPointer error returned from ResultSet.java |
Date: | 2002-10-07 15:57:28 |
Message-ID: | B9C72728.2298%jeff@alanne.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-jdbc |
Greetings,
I have a JSP page with a rather large scriptlet that uses multiple nested
statements and ResultSets. Under very specific conditions I am encountering
the following error:
java.lang.NullPointerException
at org.postgresql.jdbc2.ResultSet.next(ResultSet.java:113)
Here's one pertinent snippet of my code:
( This code begins inside a while(rs.next()) loop for ResultSet rs,
using Statement stmt)
sql.append("AN SQL QUERY");
rs2 = stmt2.executeQuery(sql.toString());
while(rs2.next()){
String courseId = rs2.getString(1);
String roleName = rs2.getString(2);
rs3 = stmt3.executeQuery("SELECT nextval('assignment_id')");
rs3.next();
assignmentId = rs3.getString(1);
sql.delete(0, sql.length());
sql.append("AN SQL QUERY");
stmt3.executeUpdate(sql.toString());
}
Through debugging it appears that rs2 is throwing the error; the message
states the error is in method next(), but if I have only zero records or
only one record in rs2, there is no error. It's only when I have multiple
records that the error is thrown the second time round the while loop, so I
suspect it may be thrown at the assignment of courseId.
This error is reproduced given the same conditions (nested ResultSets with
the innermost ResultSet executing an Update inside a while(ResultSet.next())
loop. It almost seems that the call to rs3.executeUpdate() is closing rs2,
but I cannot see why that would happen. This is occurring in at least six
different source files.
If I create a new Vector and stuff the contents of rs2 into it, then
iterate over the vector and use rs3 as shown above, no error is thrown.
Updating to the 7.3beta1 JDBC driver changes the error message to:
javax.servlet.ServletException: postgresql.con.closed
which is even more puzzling.
Notes about my coding style that may be relevant:
- I use one StringBuffer for all sql queries and clear it for each new query
for efficiency. This hasn't ever caused problems elsewhere.
- I predeclare all Statement and ResultSet objects at the outermost block of
code (the 'top') like so:
Statement stmt = conn.createStatement();
Statement stmt2 = conn.createStatement();
Statement stmt3 = conn.createStatement();
ResultSet rs, rs2, rs3;
Other data:
- The connections are obtained from a custom class that uses the jdbcpool
pool manager.
- I'm using the Sun JDK v1.4.0 for Linux (it happens on Win32 as well).
- The JDBC library is v7.2 (the pgjdbc2.jar binary download).
- PostgreSQL 7.2.1 on i686-pc-linux-gnu, compiled by GCC 2.96
Any flashes of insight?
Thanks
Jeff Duffy
jeff(at)alanne(dot)com
From | Date | Subject | |
---|---|---|---|
Next Message | Dave Cramer | 2002-10-07 16:06:17 | Re: NullPointer error returned from ResultSet.java |
Previous Message | Dave Cramer | 2002-10-07 13:43:13 | Re: jdbc cursor positioning |