15

直到今天,我一直ResultSet在处理查询结果。但今天我读了一点RowSetCachedRowset我意识到它们可以更好地服务于我的目的。虽然在所有示例中我都阅读了 whereRowSet并被CachedRowSet称为对象,但当我自己在代码中尝试时,我意识到这些是接口,并且在示例中它们使用了这些接口的一些实现。

现在我的问题是我在哪里可以找到这些实现,有什么官方的吗?

我需要下载它们还是它们随 JDK 一起提供?

4

4 回答 4

20

The implementations are JRE specific. Oracle (Sun) JRE comes with a bunch of implementations:

  • com.sun.rowset.JdbcRowSetImpl
  • com.sun.rowset.CachedRowSetImpl
  • com.sun.rowset.WebRowSetImpl
  • com.sun.rowset.FilteredRowSetImpl
  • com.sun.rowset.JoinRowSetImpl

In Java 1.6 and before, you'd need to construct them yourself:

JdbcRowSet rowSet = new JdbcRowSetImpl();
rowSet.setDataSourceName("jdbc/dbname");
// Or
rowSet.setUrl("jdbc:vendor://host:port/dbname");
rowSet.setUsername("username");
rowSet.setPassword("password");

rowSet.setCommand("SELECT id, name, value FROM tbl");
rowSet.execute();

while (rowSet.next()) {
    // ...
}

In Java 1.7 you can get them by a javax.sql.rowset factory so that you're not dependent of underlying JRE implementation and that you can finetune the implementation of choice if necessary:

RowSetFactory rowSetFactory = RowSetProvider.newFactory();
JdbcRowSet rowSet = rowSetFactory.createJdbcRowSet();
// ...

It only doesn't provide a possibility to pass a ResultSet on construction. Those implementations doesn't ship with the average JDBC driver (at least, MySQL and PostgreSQL have none). It's basically an extra (optional) layer over JDBC API as the package name prefix javax hints.

Note that if you get that far by looking into rowsets, then you might want to consider to look into an ORM instead, such as Hibernate or JPA. They provide first/second level cache possibilities.

See also:

于 2011-11-21T20:29:21.150 回答
0

和由 JDBC 驱动程序实现RowSetCachedRowSet

您的数据库提供商提供驱动程序,例如OracleMySql。但是,这些驱动程序仅在与实际数据库结合使用时才有意义。

于 2011-11-21T19:37:42.997 回答
0

它随 JDK 一起提供。

在 JDK 10 中,jar 为:jdk-10.0.2/lib/jrt-fs.jar

jar里面的包/类是:javax.sql.RowSet.class

丹尼尔·皮涅罗

danielpm1982@gmail.com

在此处输入图像描述

在此处输入图像描述

于 2018-08-22T19:17:33.927 回答
0

在 Eclipse Java 构建路径中添加 rt.jar。然后你会看到所有的实现类。否则,您可以从 Eclipse 中删除不允许从 jdk 访问 rt.jar 的限制。为我工作。我使用的是 jdk1.6 和 Eclipse Luna。

于 2019-02-07T14:56:56.057 回答