复制Java ResultSet [英] Copying Java ResultSet
问题描述
我有一个需要更新的 java.sql.ResultSet
对象。但是,结果集不可更新。不幸的是,这是我正在使用的特定框架的约束。
I have a java.sql.ResultSet
object that I need to update. However the result set is not updatable. Unfortunately this is a constraint on the particular framework I'm using.
我在这里想要实现的是从数据库中获取数据,然后操作少量数据,最后数据被写入CSV文件。
What I'm trying to achieve here is taking data from a database, then manipulating a small amount of the data and finally the data is being written to a CSV file.
在这个阶段,我认为我最好的选择是创建一个新的结果集对象并复制内容将原始结果设置为新的结果,在我这样做时操纵数据。
At this stage I think my best option is to create a new result set object and copy the contents of the original result set into the new one, manipulating the data as I do so.
然而,我在谷歌上追求高低,似乎不是能够确定如何做到这一点,或者是否甚至可以做到这一点。
However, I've hunted high and low on Google and don't seem to be able to determine how to do this or whether it's even possible at all.
我是Java的新手,所以任何帮助都会感激不尽。
I'm new to everything Java so any assistance would be gratefully received.
推荐答案
感谢您的回复。最后我找到了 CachedRowSet
这正是我所需要的。有了这个,我能够断开 ResultSet
对象并更新它。
Thanks for the responses. In the end I found CachedRowSet
which is exactly what I needed. With this I was able to disconnect the ResultSet
object and update it.
还有,因为 CachedRowSet
实现 ResultSet
接口我仍然可以将它传递给我的文件生成方法,该方法需要一个实现ResultSet的对象。
What's more, because CachedRowSet
implements the ResultSet
interface I was still able to pass it to my file generation method which requires an object that implements ResultSet.
这篇关于复制Java ResultSet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!