RowSet、CachedRowSet 等的实现 [英] Implementations of RowSet, CachedRowSet etc

查看:19
本文介绍了RowSet、CachedRowSet 等的实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Until today I was working with ResultSet when handling results from queries. But today I read a little about RowSet and CachedRowset and I realized they can serve my purposes better. While in all the examples I read where RowSet and CachedRowSet were referred to as object, when I tried it myself in my code I realized those are interfaces and in the examples they use some implementation of those interfaces.

现在我的问题是我在哪里可以找到这些实现,有没有官方的东西?

Now my question is where do I find those implementations, and is there something official?

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

Do I need to download them or do they come with the JDK?

推荐答案

实现是特定于 JRE 的.Oracle (Sun) JRE 带有一堆实现:

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

在 Java 1.6 及更早版本中,您需要自己构建它们:

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()) {
    // ...
}

在 Java 1.7 中,您可以通过 javax.sql.rowset 工厂获取它们,以便您不依赖于底层 JRE 实现,并且您可以在必要时微调选择的实现:

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();
// ...

它只是不提供在构造时传递 ResultSet 的可能性.这些实现不附带普通的 JDBC 驱动程序(至少,MySQL 和 PostgreSQL 没有).它基本上是 JDBC API 之上的一个额外(可选)层,作为包名称前缀 javax 提示.

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.

请注意,如果您通过查看行集得到了那么远,那么您可能需要考虑查看 ORM,例如 Hibernate 或 JPA.它们提供一级/二级缓存的可能性.

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.

  • JDBC Guide - Chapter 10 - RowSet
  • JDBC RowSet tutorial, by Oracle
  • Java 8 javax.sql.rowset package summary
  • Source code in OpenJDK 8 for Oracle’s com.sun.rowset implementation, Gnu GPL 2 license with Classpath exception

这篇关于RowSet、CachedRowSet 等的实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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