Can i use a resultset more than once without closing it
Printable View
Can i use a resultset more than once without closing it
What do you mean? You can use it until you get all the data out of it. If it has more than one row you use it more than once.
You cannot use the resultset more than once...
Once you have called the next row(), the resultset cannot be called back to the previous row...
Yes, you can do whatever you want before close the result set if you render a single data row. If you have multiple rows, after calling a one you can use the previous one. Basically the new one overwrite the new.(don't confused this with memory)
Yes you can, create a Scrollable ResultSet (see the API docs for the createStatement() method), scroll through it with next(), then call either beforeFirst() and scroll through it with next() again. The only question is why?
If the ResultSet is not too large, why don't you just save the rows to an ArrayList as you go through it the first time, then use that ArrayList for any further actions? That would completely eliminate any network latency on additional reads.
Yes you can. ^_^
Ive done it, Im using 3 Result Set in a for loop. I used them to save connection in the port for multiple batch processing. And it is also possible to return to the previous row or any Row you would like. You Just to set the following
Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSIT IVE, ResultSet.CONCUR_READ_ONLY); <-- Scrollable but Read Only
Statement stmt2 = con.createStatement(ResultSet.TYPE_SCROLL_INSENSIT IVE, ResultSet.CONCUR_UPDATABLE); <-- Scrollable and editable but requires a single connection
then you can invoke the ff:
rs.beforefirst() or rs.first() to return to the start
rs.previous() to return one row back
rs.afterLast() or rs.last() to go the last part if you want to insert a new Row
rs.absolute(int X) <--to go to a specific Row
But I think i masijade's solution to save it to a arraylist is a better approach if you will only need to get data from the database ^_^