What Is a JdbcRowSet? JDBC

JdbcRowSet (javax.sql.JdbcRowSet interface) is a connected rowset that serves mainly as a thin wrapper around a ResultSet object to make a JDBC driver look like a JavaBeans component. According to J2SE 5.0 documentation, “a JdbcRowSet object can be one of the Beans that a tool makes available for composing an application. Because a JdbcRowSet is a connected rowset, that is, it continually maintains its connection to a database using a JDBC technologyenabled driver, it also effectively makes the driver a JavaBeans component.” JdbcRowSet is defined as follows:

Because JdbcRowSet is always connected to its database, an instance of JdbcRowSet can simply take calls invoked on it and in turn call them on its ResultSet object. As a consequence, a result set can, for example, be a component in a Swing application. Another advantage of a JdbcRowSet object is that it can be used to make a ResultSet object scrollable and updatable. All RowSet objects are by default scrollable and updatable. If the driver and database being used do not support scrolling or updating of result sets, an application can populate a JdbcRowSet object with the data of a ResultSet object and then operate on the JdbcRowSet object as if it were the ResultSet object.

The following code fragment illustrates creating a JdbcRowSet object, setting its properties, and executing the command string in its command property:

At this point, jrs contains all of the selected data in the books table. After creating a JdbcRowSet object, you may use ResultSet methods because it is effectively operating on a ResultSet object. It can navigate the rows in jrs, retrieve column values, update column values, insert new rows, and so on. For example, to process results, you may write the following to iterate all rows:

In this example, the next three lines of code go to the fifth row and retrieve the value in the first and second columns using ResultSet methods:

Once you create a JdbcRowSet object, then you can extract its metadata by using this code (note that the method getMetaData() is a ResultSet method that returns a ResultSetMetaData object, so it must be cast to a RowSetMetaData object before it can be assigned to rsMetaData):

For rowset objects, you may pass input parameters (similar to PreparedStatement objects). The following code fragment shows what an application might do: it sets the rowset’s command, sets the command’s parameters, and executes the command. Simply by calling the execute method, jrs populates itself with the requested data from the table CUSTOMERS:

Sun’s reference implementation class, com.sun.rowset.JdbcRowSetImpl, which is defined next, has four constructors. In order to understand the JdbcRowSetImpl class, we need to understand the BaseRowSet class—the superclass for the JdbcRowSetImpl class.

BaseRowSet Class Definition

According to the JDBC 3.0 Specification (implemented in JDK 1.5), the BaseRowSet is an abstract class providing a RowSet object with its basic functionality. The basic functions include having properties and sending event notifications, which all JavaBeans components must implement. The BaseRowSet class provides the core functionality for all RowSet implementations, and all standard implementations may use this class in combination with one or more RowSet interfaces in order to provide a standard vendor-specific implementation. To clarify, all implementations must implement at least one of the RowSet interfaces (JdbcRowSet, CachedRowSet, JoinRowSet, FilteredRowSet, or WebRowSet). This means that any implementation that extends the BaseRowSet class must also implement one of the RowSet interfaces.

The BaseRowSet class provides the following:

  • Properties
  • Fields for storing current properties
  • Methods for getting and setting properties
  • Event notification
  • A complete set of setter methods for setting the parameters in a RowSet object’s command
  • Streams
  • Fields for storing stream instances
  • Constants for indicating the type of a stream

JdbcRowSetImpl Class Definition

Here, the javax.sql.rowset.Joinable interface provides the methods for getting and setting a match column, which is the basis for forming the SQL JOIN formed by adding RowSet objects to a JoinRowSet object.

JdbcRowSetImpl Class Constructors

  • JdbcRowSetImpl(): Constructs a default JdbcRowSet object
  • JdbcRowSetImpl(java.sql.Connection con): Constructs a default JdbcRowSet object given a valid Connection object
  • JdbcRowSetImpl(java.sql.ResultSet res): Constructs a JdbcRowSet object using the given valid ResultSet object
  • JdbcRowSetImpl(String url, String user, String password): Constructs a default JdbcRowSet object using the URL, username, and password arguments supplied

Face Book Twitter Google Plus Instagram Youtube Linkedin Myspace Pinterest Soundcloud Wikipedia

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

JDBC Topics