Is there a way in Java to delete a row just from a result set and not from underlying database? Thanks.
Java中是否有一种方法可以仅从结果集而不是从底层数据库中删除行?谢谢。
3 个解决方案
#1
3
Take a look at the CachedRowSet
. It allows you to create a disconnected ResultSet
and operate without affecting the database.
看看CachedRowSet。它允许您创建断开连接的ResultSet并在不影响数据库的情况下运行。
#2
0
It sounds like you're iterating through your ResultSet and filtering rows as you go?
听起来你正在迭代你的ResultSet并过滤你的行?
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.
如果可以的话,我会说要么将过滤移动到SQL语句,否则将ResultSet复制到List中,如果你不愿意将rowtype的对象或Map的副本复制,然后调用list.remove(row)。
You can't remove rows or update a ResultSet, you'd have to use a CachedRowSet like VAShhh suggests.
您无法删除行或更新ResultSet,您必须使用像VAShhh建议的CachedRowSet。
#3
0
You can solve that problem by setting setAutoCommit()
on your connection object to false, e.g conn.setAutoCommit(false)
.
您可以通过将连接对象上的setAutoCommit()设置为false来解决该问题,例如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.
然后执行所有删除操作,之后在连接对象上调用rollback():conn.rollback()。这将反转您所做的所有删除并使数据库保持原始状态。
#1
3
Take a look at the CachedRowSet
. It allows you to create a disconnected ResultSet
and operate without affecting the database.
看看CachedRowSet。它允许您创建断开连接的ResultSet并在不影响数据库的情况下运行。
#2
0
It sounds like you're iterating through your ResultSet and filtering rows as you go?
听起来你正在迭代你的ResultSet并过滤你的行?
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.
如果可以的话,我会说要么将过滤移动到SQL语句,否则将ResultSet复制到List中,如果你不愿意将rowtype的对象或Map的副本复制,然后调用list.remove(row)。
You can't remove rows or update a ResultSet, you'd have to use a CachedRowSet like VAShhh suggests.
您无法删除行或更新ResultSet,您必须使用像VAShhh建议的CachedRowSet。
#3
0
You can solve that problem by setting setAutoCommit()
on your connection object to false, e.g conn.setAutoCommit(false)
.
您可以通过将连接对象上的setAutoCommit()设置为false来解决该问题,例如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.
然后执行所有删除操作,之后在连接对象上调用rollback():conn.rollback()。这将反转您所做的所有删除并使数据库保持原始状态。