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.
Articles Related
Interfaces
The following interfaces extend the RowSet interface:
- JdbcRowSet, Always connected
- CachedRowSet, Disconnected, Java's answer to a “disconnected” ResultSet. Unlike a ResultSet, a CachedRowSet stores all rows obtained from a query in local memory.
- WebRowSet, Disconnected
- JoinRowSet, Disconnected
- FilteredRowSet, Disconnected
Implementation
Implementations of RowSet will normally be provided by third-party database vendors.
Default implementation are given by Sun:
- JdbcRowSetImpl
- CachedRowSetImpl
- …
Properties
Connected / Disconnected
A RowSet object is considered either connected or disconnected.
- A connected RowSet object uses a JDBC driver to make a connection to a relational database and maintains that connection throughout its life span.
- 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. They do not maintain a connection to a database. Instead, they reconnect only when making database changes or when repopulating the database with data. After reading data from or writing data to its data source, the RowSet object disconnects from it, thus becoming “disconnected.” During much of its life span, a disconnected RowSet object has no connection to its data source and operates independently. Disconnected RowSet objects are also serializable, and the combination of being both serializable and lightweight makes them ideal for sending data over a network.
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:
- A cursor movement
- The update, insertion, or deletion of a row
- 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:
- type: ResultSet.TYPE_SCROLL_INSENSITIVE (has a scrollable cursor)
- concurrency: ResultSet.CONCUR_UPDATABLE (can be updated)
- escapeProcessing: true (the driver will do escape processing; when escape processing is enabled, the driver will scan for any escape syntax and translate it into code that the particular database understands)
- maxRows: 0 (no limit on the number of rows)
- maxFieldSize: 0 (no limit on the number of bytes for a column value; applies only to columns that store BINARY, VARBINARY, LONGVARBINARY, CHAR, VARCHAR, and LONGVARCHAR values)
- queryTimeout: 0 (has no time limit for how long it takes to execute a query)
- showDeleted: false (deleted rows are not visible)
- transactionIsolation: Connection.TRANSACTION_READ_COMMITTED (reads only data that has been committed)
- typeMap: null (the type map associated with a Connection object used by this RowSet object is null)
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:
- connection is a SQL connection