开发者

Deleting row from Java ResultSet and not from underlying database

开发者 https://www.devze.com 2023-03-14 05:57 出处:网络
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 ResultSe

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号