问题
If I have to loop two times after each other using while(rs.next()) for different reasons through the same ResultSet, what can I do so that the ResultSet doesn't close automatically and to prevent the 'ResultSet is closed Exception'? I tried using resultset.first() to move the cursor back to the first row after the first loop but this error fired even on this statement!
回答1:
This depends on your driver used.
Some driver are not able to reset a ResultSet. In this case you will get an Exception when calling first().
You can check in the Statement with a call to getResultSetType() if your driver supports scrolling in a ResultSet.
If possible try to do your two things in one iteration as you never know if you can iterate a second time over a ResultSet.
来源:https://stackoverflow.com/questions/17450766/move-cursor-to-first-row-after-while-loop-resultset