Sunday, March 30, 2014

What is JDBC RowSet ?

A RowSet ( javax.sql.RowSet ) is an object that encapsulates a set of rows from either Java Database Connectivity (JDBC) result sets or tabular data sources like a file or spreadsheet. RowSets support component-based development models like JavaBeans, with a standard set of properties and an event notification mechanism.

Interfaces that extends RowSet are  :
  • JdbcRowSet
  • CachedRowSet
  • WebRowSet
  • JoinRowSet
  • FilteredRowSet

Benefits :
Beside sharing the capabilities of a ResultSet , RowSet adds the following new capabilities :

1.  Function as JavaBeans Component
That means RowSet objects have properties with corresponding getter and setter methods that can be exposed to builder tools (such as those that come with the IDEs JDveloper and Eclipse) that provides the capability to visually manipulate the beans.

In addition , RowSet objects use the JavaBeans event model, in which registered components are notified when certain events occur. The events that trigger notifications are :
  • A cursor movement
  • The update, insertion, or deletion of a row
  • A change to the entire RowSet contents

2.  Add Scrollability or Updatability
If a database driver does not have the ability to scroll or update result sets, RowSet object can be used for the same . 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.

Types of Rowset :
There are two types of RowSet :
  • Connected - A connected RowSet object connects to the database once and remains connected until the application terminates. Only one of the standard RowSet implementations is a connected RowSet object - JdbcRowSet.
  • Disconnected - A disconnected RowSet object connects to the database, executes a query to retrieve the data from the database and then closes the connection. A program may change the data in a disconnected RowSet while it is disconnected. Modified data can be updated in the database after a disconnected RowSet reestablishes the connection with the database.Disconnected RowSet objects are lightweight and  serializable, and it makes them ideal for sending data over a network. They can even be used for sending data to thin clients such as PDAs and mobile phones.

No comments :

Post a Comment