CachedRowSet:它还能用来保存 ResultSet 数据吗? [英] CachedRowSet: can it still be used to hold ResultSet data?

查看:55
本文介绍了CachedRowSet:它还能用来保存 ResultSet 数据吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想编写一个 java 函数,它接受一个 SQL 查询并返回一个 ResultSet 以便在其他地方进行处理.这不能完成,因为一旦连接关闭,ResultSet 就死了.

I would like to write a java function that takes in a SQL query and returns a ResultSet for processing elsewhere. This can't be done as a ResultSet is dead once the connection is closed.

在谷歌上搜索我发现了一篇 非常老 (2004) OReilly 的文章 看起来像治疗方法的东西:CachedRowSet.您只需放入 ResultSet,CachedRowSet 会保存数据,让您关闭连接并使用返回的 CachedRowSet 在别处处理数据.

Googling around I found a VERY OLD (2004) OReilly article that had something that looked like the cure: CachedRowSet. You just drop in your ResultSet, the CachedRowSet saves the data, lets you close the connection and play with the data elsewhere using the returned CachedRowSet.

这篇文章引用了 Sun 的 CachedRowSet 实现,但似乎无处可寻.

The article references implementations of the CachedRowSet by Sun, which appear to be nowhere to be found.

现代 javadocs(用于 Java 1.5 及更高版本)似乎有同名的东西,CachedRowSet",它不仅仅是一个 ResultSet 数据的持有者.CachedRowSet"似乎从获取连接和其他所有内容来完成整个数据库处理.

Modern javadocs ( for Java 1.5 and up ) seem to have something by the same name, "CachedRowSet", that is more than just a holder of ResultSet data. That "CachedRowSet" seems to do the entire database processing from getting connections and everything else.

CachedRowSet"是否与旧文章中讨论的相同?

Is THAT "CachedRowSet" the same thing as is talked about in the old article?

我想要一些简单的东西,就像在旧文章中一样.在连接关闭后将 ResultSet 放入其中进行处理.

I would like something simple, like in the old article. Something to plop a ResultSet into for processing after the conneciton is closed.

有这种动物吗?

谢谢

推荐答案

CachedRowSet 是一个标准的 Java 接口.Sun写了一个参考实现,Sun/Oracle JDK 包含它.如果您使用的是不同的 JDK,则该实现或其他实现可能可用,也可能不可用.

CachedRowSet is a standard Java interface. Sun wrote a reference implementation, and the Sun/Oracle JDK contains it. If you're using a different JDK, that or another implementation may or may not be available.

如果您已经有一个 ResultSet,那么您可以使用 populate 方法.

If you already have a ResultSet, then you can fill a CachedRowSet from it using the populate method.

如果您有足够的前瞻性来使用 Java 7,那么您可以使用 RowSetFactory,它有一个 createCachedRowSet 方法.您可以从 RowSetProvider(当然!).

If you are forward-thinking enough to be using Java 7, then you can obtain a CachedRowSet instance in a portable way, using a RowSetFactory, which has a createCachedRowSet method. You can get a RowSetFactory from a RowSetProvider (of course!).

这篇关于CachedRowSet:它还能用来保存 ResultSet 数据吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆