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

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

问题描述

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

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

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

它只提供传递<的可能性code> 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天全站免登陆