NASRowSet class
A RowSet is an object that encapsulates a set of rows retrieved from a database or other tabular data store, such as a spreadsheet. To implement a RowSet, your code must import javax.sql, and implement the RowSet interface. RowSet extends the java.sql.ResultSet interface, permitting it to act as a JavaBeans component.
Because a RowSet is a JavaBean, you can implement events and event listeners for the RowSet, and you can set properties on the RowSet. Furthermore, because RowSet is an extension of ResultSet, you can iterate through a RowSet just as you would iterate through a result set.
You fill a RowSet by calling the RowSet.execute( ) method. The execute( ) method uses property values to determine the data source and retrieve data. The properties you decide to set and examine depend on the implementation of RowSet you invoke.
Package
com.netscape.server.jdbc
Constructors
In a NAS application, you can create a RowSet in either of two ways:
NASRowSet rs = new NASRowSet();
You can create NAS-independent code. To do so, call new on the InitialContext class. Then, using this InitialContext, look up the class that implements the RowSet interface: InitialContext ctx = new InitialContext();
RowSet rs = (javax.sql.RowSet) ctx.lookup("javax.sql.RowSet");
The ctx.lookup( ) call returns an instance of the class that is bound to the implementation of javax.sql.RowSet. In this case, the class that is bound is NASRowSet.
Methods
This section provides details about what NASRowSet implements.
NASRowSet is a class that extends ResultSet, so the NASRowSet methods are inherited from the ResultSet object.
In addition, NASRowSet does the following:
RowSet interface
The RowSet interface is fully supported except as noted in the following table:
RowSetReader interface
NASRowSet provides a full implementation of the RowSetReader interface. As an alternative to one of the RowSetReader methods, you can use the setReaderMethod( ) from the CachedRowSet class. The argument of setReaderMethod( ) must nonetheless implement the RowSetReader interface.
RowSetWriter interface
Although NASRowSet is read-only, it implements the RowSetWriter interface for future use. The only method of RowSetWriter, writeData( ), throws SQLException when called, indicating that this method is not supported.
RowSetInternal interface
This internal interface is called by a method of the RowSetReader interface to retrieve information about the RowSet. RowSetInternal has a single method, getOriginalRow( ), which returns the entire result set instead of a single row.
CachedRowSet class
Sun provides a rowset class named CachedRowSet, which is an implementation of the RowSet interface. CachedRowSet lets you retrieve data from a data source, then detach from the data source while you examine (and modify) the data. A cached rowset keeps track of not only the original data retrieved, but also any data changes your application made. If the application trys to update the original data source, the rowset is reconnected to the data source, and only those rows that have changed are merged back into the database.
NASRowSet implements many of the methods in the CachedRowSet class because they're useful. However, NASRowSet does not implement all the methods. Unimplemented methods throw SQLException if called. The following CachedRowSet methods throw SQLException because NASRowSet is read-only:
The toCollection( ) method throws SQLException because collections are a JDK 1.2 feature.
SqlUtil class
The SqlUtil class is part of the NAS Foundation Class Library. This class contains loadQuery( ), a method that supports rowsets. The loadQuery( ) method can be used on the RowSet interface in place of the setCommand( ) method.
For example:
import com.kivasoft.util.SqlUtil;
...
SqlUtil.loadQuery(rowset, pathname, queryname, params);
This version of loadQuery( ) reads the queryname from the file specified by pathname. The method then replaces parameters according to params (an IValList object) and sets the query command as the RowSet query command.
Related Topics
RowSet, RowSetInternal, RowSetReader, or RowSetWriter interfaces in the javax.sql package, java.sql.ResultSet interface, com.kivasoft.util.SqlUtil class
Using JDBC for Database Access
|