Move cursor to first row after while loop ResultSet

荒凉一梦 提交于 2019-12-11 03:13:45

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!