Deleting row from Java ResultSet and not from underlying database
Is there a way in Java to delet开发者_如何转开发e a row just from a result set and not from underlying database? Thanks.
Take a look at the CachedRowSet
. It allows you to create a disconnected ResultSet
and operate without affecting the database.
It sounds like you're iterating through your ResultSet and filtering rows as you go?
I would say either move the filtering to the SQL statement if you can, otherwise copy the ResultSet into a List, either of objects of rowtype or just Map's if you'd rather not, then call list.remove(row) as you go.
You can't remove rows or update a ResultSet, you'd have to use a CachedRowSet like VAShhh suggests.
You can solve that problem by setting setAutoCommit()
on your connection object to false, e.g conn.setAutoCommit(false)
.
Then perform all your deletes, after which you call rollback()
on the connection object: conn.rollback()
. This will reverse all the delete that you made and keep your database at the original state.
精彩评论