The Java Tutorials have been written for JDK 8.Java教程是为JDK 8编写的。Examples and practices described in this page don't take advantage of improvements introduced in later releases and might use technology no longer available.本页中描述的示例和实践没有利用后续版本中引入的改进,并且可能使用不再可用的技术。See Java Language Changes for a summary of updated language features in Java SE 9 and subsequent releases.有关Java SE 9及其后续版本中更新的语言特性的摘要,请参阅Java语言更改。
See JDK Release Notes for information about new features, enhancements, and removed or deprecated options for all JDK releases.有关所有JDK版本的新功能、增强功能以及已删除或不推荐的选项的信息,请参阅JDK发行说明。
A JDBC JDBCRowSet
object holds tabular data in a way that makes it more flexible and easier to use than a result set.RowSet
对象以一种比结果集更灵活、更易于使用的方式保存表格数据。
Oracle has defined five Oracle为RowSet
interfaces for some of the more popular uses of a RowSet
, and standard reference are available for these RowSet
interfaces. RowSet
的一些更流行的用途定义了五个RowSet
接口,这些RowSet
接口提供了标准参考。In this tutorial you will learn how to use these reference implementations.在本教程中,您将学习如何使用这些参考实现。
These versions of the 为方便程序员,提供了这些版本的RowSet
interface and their implementations have been provided as a convenience for programmers. RowSet
接口及其实现。Programmers are free to write their own versions of the 程序员可以自由编写自己版本的javax.sql.RowSet
interface, to extend the implementations of the five RowSet
interfaces, or to write their own implementations. javax.sql.RowSet
接口,扩展五个RowSet
接口的实现,或者编写自己的实现。However, many programmers will probably find that the standard reference implementations already fit their needs and will use them as is.然而,许多程序员可能会发现标准参考实现已经满足了他们的需求,并将按原样使用它们。
This section introduces you to the 本节向您介绍RowSet
interface and the following interfaces that extend this interface:RowSet
接口以及扩展此接口的以下接口:
JdbcRowSet
CachedRowSet
WebRowSet
JoinRowSet
FilteredRowSet
The following topics are covered:涵盖以下主题:
All 所有RowSet
objects are derived from the ResultSet
interface and therefore share its capabilities. RowSet
对象都派生自ResultSet
接口,因此共享其功能。What makes JDBC JDBCRowSet
objects special is that they add these new capabilities:RowSet
对象的特殊之处在于它们添加了以下新功能:
All 所有RowSet
objects are JavaBeans components. RowSet
对象都是JavaBeans组件。This means that they have the following:这意味着他们具备以下条件:
All 所有RowSet
objects have properties. RowSet
对象都具有属性。A property is a field that has corresponding getter and setter methods. 属性是具有相应的getter和setter方法的字段。Properties are exposed to builder tools (such as those that come with the IDEs JDveloper and Eclipse) that enable you to visually manipulate beans. 属性向构建器工具(例如IDE JDDeveloper和Eclipse附带的工具)公开,这些工具使您能够直观地操作bean。For more information, see the Properties lesson in the JavaBeans trail.有关更多信息,请参阅JavaBeans教程中的属性课程。
RowSet
objects use the JavaBeans event model, in which registered components are notified when certain events occur. RowSet
对象使用JavaBeans事件模型,在该模型中,当某些事件发生时,会通知已注册的组件。For all 对于所有RowSet
objects, three events trigger notifications:RowSet
对象,有三个事件触发通知:
RowSet
contentsRowSet
内容的更改The notification of an event goes to all listeners, components that have implemented the 事件的通知将发送给所有侦听器,这些侦听器是已实现RowSetListener
interface and have had themselves added to the RowSet
object's list of components to be notified when any of the three events occurs.RowSetListener
接口并已将其自身添加到RowSet
对象的组件列表中的组件,这些组件将在三个事件中的任何一个发生时收到通知。
A listener could be a GUI component such as a bar graph. 侦听器可以是GUI组件,如条形图。If the bar graph is tracking data in a 如果条形图正在跟踪RowSet
object, the listener would want to know the new data values whenever the data changed. RowSet
对象中的数据,则侦听器希望在数据更改时了解新的数据值。The listener would therefore implement the 因此,侦听器将实现RowSetListener
methods to define what it will do when a particular event occurs. RowSetListener
方法,以定义在特定事件发生时它将执行的操作。Then the listener also must be added to the 然后,还必须将侦听器添加到RowSet
object's list of listeners. RowSet
对象的侦听器列表中。The following line of code registers the bar graph component 以下代码行将条形图组件bg
with the RowSet
object rs
.bg
注册到RowSet
对象rs
。
rs.addListener(bg);
Now 现在,每当游标移动、行更改或所有bg
will be notified each time the cursor moves, a row is changed, or all of rs
gets new data.rs
获得新数据时,bg
都会收到通知。
Some DBMSs do not support result sets that can be scrolled (scrollable), and some do not support result sets that can be updated (updatable). 有些DBMS不支持可滚动(可滚动)的结果集,有些DBMS不支持可更新(可更新)的结果集。If a driver for that DBMS does not add the ability to scroll or update result sets, you can use a 如果该DBMS的驱动程序没有添加滚动或更新结果集的功能,则可以使用RowSet
object to do it. RowSet
对象来执行此操作。A 默认情况下,RowSet
object is scrollable and updatable by default, so by populating a RowSet
object with the contents of a result set, you can effectively make the result set scrollable and updatable.RowSet
对象是可滚动和可更新的,因此通过使用结果集的内容填充行集对象,可以有效地使结果集可滚动和可更新。
A RowSet
object is considered either connected or disconnected. RowSet
对象被视为已连接或已断开连接。A connected 已连接的RowSet
object uses a JDBC driver to make a connection to a relational database and maintains that connection throughout its life span. RowSet
对象使用JDBC驱动程序与关系数据库建立连接,并在其整个生命周期内维护该连接。A disconnected 断开连接的RowSet
object makes a connection to a data source only to read in data from a ResultSet
object or to write data back to the data source. RowSet
对象与数据源建立连接,只是为了从ResultSet
对象读入数据或将数据写回数据源。After reading data from or writing data to its data source, the 在从其数据源读取数据或将数据写入数据源后,RowSet
object disconnects from it, thus becoming "disconnected." RowSet
对象将与其断开连接,从而变为“断开连接”。During much of its life span, a disconnected 在其生命周期的大部分时间内,断开连接的RowSet
object has no connection to its data source and operates independently. RowSet
对象与其数据源没有连接,并且独立运行。The next two sections tell you what being connected or disconnected means in terms of what a 接下来的两部分将告诉您,就RowSet
object can do.RowSet
对象的功能而言,连接或断开连接意味着什么。
Only one of the standard 标准RowSet
implementations is a connected RowSet
object: JdbcRowSet
. RowSet
实现中只有一个是连接的RowSet
对象:JdbcRowSet
。Always being connected to a database, a JdbcRowSet
object is most similar to a ResultSet
object and is often used as a wrapper to make an otherwise non-scrollable and read-only ResultSet
object scrollable and updatable.JdbcRowSet
对象始终连接到数据库,它与ResultSet
对象最为相似,通常用作包装器,以使原本不可滚动且只读的ResultSet
对象可滚动且可更新。
As a JavaBeans component, a 作为JavaBeans组件,例如,可以在GUI工具中使用JdbcRowSet
object can be used, for example, in a GUI tool to select a JDBC driver. JdbcRowSet
对象来选择JDBC驱动程序。A JdbcRowSet
object can be used this way because it is effectively a wrapper for the driver that obtained its connection to the database.JdbcRowSet
对象可以这样使用,因为它实际上是获得数据库连接的驱动程序的包装器。
The other four implementations are disconnected 其他四种实现是断开连接的RowSet
implementations. RowSet
实现。Disconnected 断开连接的RowSet
objects have all the capabilities of connected RowSet
objects plus they have the additional capabilities available only to disconnected RowSet
objects. RowSet
对象具有连接的RowSet
对象的所有功能,并且它们具有仅对断开连接的RowSet
对象可用的附加功能。For example, not having to maintain a connection to a data source makes disconnected 例如,不必维护与数据源的连接,使断开连接的RowSet
objects far more lightweight than a JdbcRowSet
object or a ResultSet
object. RowSet
对象比JdbcRowSet
对象或ResultSet
对象轻得多。Disconnected 断开连接的RowSet
objects are also serializable, and the combination of being both serializable and lightweight makes them ideal for sending data over a network. RowSet
对象也是可序列化的,可序列化和轻量级的结合使它们非常适合通过网络发送数据。They can even be used for sending data to thin clients such as PDAs and mobile phones.它们甚至可以用于向PDA和移动电话等轻客户端发送数据。
The CachedRowSet
interface defines the basic capabilities available to all disconnected RowSet
objects. CachedRowSet
接口定义了所有断开连接的RowSet
对象可用的基本功能。The other three are extensions of the 另外三个是CachedRowSet
interface, which provide more specialized capabilities. CachedRowSet
接口的扩展,它提供了更专门的功能。The following information shows how they are related:以下信息显示了它们之间的关系:
A CachedRowSet
object has all the capabilities of a JdbcRowSet
object plus it can also do the following:CachedRowSet
对象具有JdbcRowSet
对象的所有功能,并且还可以执行以下操作:
ResultSet
object and populate itself with that dataResultSet
对象中读取数据并用该数据填充自身A WebRowSet
object has all the capabilities of a CachedRowSet
object plus it can also do the following:WebRowSet
对象具有CachedRowSet
对象的所有功能,并且还可以执行以下操作:
WebRowSet
objectWebRowSet
对象的XML文档A JoinRowSet
object has all the capabilities of a WebRowSet
object (and therefore also those of a CachedRowSet
object) plus it can also do the following:JoinRowSet
对象具有WebRowSet
对象(因此也具有CachedRowSet
对象)的所有功能,此外,它还可以执行以下操作:
SQL JOIN
without having to connect to a data sourceSQL JOIN
的形式A FilteredRowSet
object likewise has all the capabilities of a WebRowSet
object (and therefore also a CachedRowSet
object) plus it can also do the following:FilteredRowSet
对象同样具有WebRowSet
对象(因此也是CachedRowSet
对象)的所有功能,并且还可以执行以下操作:
RowSet
object without having to use a query language or connect to a data source.RowSet
对象执行查询,而不必使用查询语言或连接到数据源。