Table of Contents

Jdbc - Rowset

About

A RowSet is an extension of a Java ResultSet. Like a result set, a rowset is a Java object that holds tabular data. A RowSet object is scrollable and updatable by default,

One of the main uses of a RowSet object is to make a ResultSet object scrollable and updatable when the DBMS driver does not otherwise have those capabilities. By populating a RowSet object with the contents of a ResultSet, you can effectively make the result set scrollable and updatable.

Interfaces

The following interfaces extend the RowSet interface:

Implementation

Implementations of RowSet will normally be provided by third-party database vendors.

Default implementation are given by Sun:

Properties

Connected / Disconnected

A RowSet object is considered either connected or disconnected.

Serializable

A RowSet object is a JavaBeans component, and it may operate without being connected to its data source.

For example, a RowSet implementation can be serializable and therefore sent across a network, which is particularly useful for small-footprint clients that want to operate on tabular data without incurring the overhead of a JDBC driver and data source connection.

Custom reader and writer

Another feature of a RowSet implementation is that it can include a custom reader for accessing any data in tabular format, not just data in a relational database. Further, a RowSet object can update its rows while it is disconnected from its data source, and its implementation can include a custom writer that writes those updates back to the underlying data source.

Event notification

RowSet objects use the JavaBeans event model, in which registered components are notified when certain events occur. For all RowSet objects, three events trigger notifications:

  1. A cursor movement
  2. The update, insertion, or deletion of a row
  3. A change to the entire RowSet contents

Default Properties

When you create a JdbcRowSet object with the default constructor, the new JdbcRowSet object will have the following properties:

CachedRowSet

Populate

CachedRowSetImpl crs = new CachedRowSetImpl();
crs.populate(resultSet);

Update

jdbcRs.absolute(3);
jdbcRs.updateFloat("PRICE", 10.99f);
jdbcRs.updateRow();

Insert

jdbcRs.moveToInsertRow();
jdbcRs.updateString("COF_NAME", "HouseBlend");
jdbcRs.updateInt("SUP_ID", 49);
jdbcRs.updateFloat("PRICE", 7.99f);
jdbcRs.updateInt("SALES", 0);
jdbcRs.updateInt("TOTAL", 0);
jdbcRs.insertRow();

Delete

jdbcRs.last();
jdbcRs.deleteRow();

Propagate Change to the DB

cachedRowSet.acceptChanges(connection);

where:

Documentation / Reference