ResultSet closed

I'm doing some JSP/Servlet/JDBC coding. I let the servlet connect to the database. I finally came to the part of simply displaying the data in JSP with the obtained ResultSet. I didn't close any of the ResultSets (in the servlet). But when I forward the request/response to a JSP (for displaying), and get the Attributes I have set (the ResultSets), I getting a closed ResultSet (which cannot be displayed obviously).

That ResultSet has 1 row, 3 columns. I only got a string from it (i.e. getString("username")). But I didn't close it. When I did a debug, it was closed.

Is forwarding a response/request closing any ResultSet that was obtained before?

[681 byte] By [deandaniel] at [2007-9-26 2:32:53]
# 1

Did the statement or connection go out of scope? did you close the connection or statement? The resultset will be closed if the connection or statement is closed or is out of scope. if you don't want the ResultSet tied to a Statement/Connection then use a CachedRowSet instead.

Jamie

jlrober at 2007-6-29 9:55:06 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2
thanks for your reply. I didn't close anything at all (connection, statement, resultset, etc. ) I just forwarded an object to a JSP from the servlet. anyway, I'll see the CachedRowSet.
deandaniel at 2007-6-29 9:55:06 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 3
What do you mean 'forward'?Presumably everything is running in the same JVM.Are connection and statement held in a singleton instance (static?) Or are they passed along with the ResultSet?If the answer to both of the above is no, then they are (or can be) closed.
jschell at 2007-6-29 9:55:06 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 4

Can you post your JDBC source code? Without knowing at least the sniplets of your code, it is quite difficult to determine if the connection made to the database is closed by your code.

In general, the ResultSet object is linked to its parent 'Statement'. Therefore if a Statement is closed or used to execute another query, any related ResultSet objects are closed automatically.

Allen Lai

SUN Developer Technical Support

allenlai at 2007-6-29 9:55:06 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...