Usage of RowSet (1)

zhaozj2021-02-16  58

RowSet is an interface model for operating a table column data in a disconnected and connected environment. Rowset includes two important set classes: CachedRowSet, FilteredrowSet, JDBcrowSet, Joinable, JoinRowSet, Predicate, WebrowSet. Where CachedRowSet and JDBcrowSet apply the most.

1. CachedRowset

CachedRowSet has two important roles. First, the data from the database is passed between multiple components of the application, and the second is that the package resultset provides scrolling, updatable result set.

Since cachedrowset is Disconnected for the database, it is just when data is acquired from the data source and the database is Connected when updating the data source. Therefore, it can deliver data between different components without having to keep connected with the data source, such as clients that run the EJB component query running on the server side via NET to the web browser.

The CachedRowSet provides the table data to locate each line of features, such as Forward, Backward or to a specific row (this resultset is not available); at the same time, the packaged data is also updated, and after the data is updated, as long as Call the acceptchange (); method to update the data to the data source.

Such as:

ResultSet RS = Stmt.executeQuery ("Select * from Employees);

CachedRowSet CRS = New CachedRowSet ();

Crs.Populate (RS);

Crs.movetoInsertrow ();

Crs.UpdateString ("Name", "Shakespeare");

Crs.UpdateInt ("ID", 10098347);

Crs.Updateshort ("Age", 58);

Crs.UpdateInt ("SAL", 150000);

Crs.inSertrow ();

Crs.movetocurrentrow ();

Crs.acceptchanges ();

In addition to these effects, it also provides a listener mechanism to retrieve RowSetMetadata

In addition, CachedRowSet also provides a PrepareStatement function similar to the Resultset.

Crs.SetCommand ("SELECT First_Name, Last_Name, Address from Customers " Where Credit_Limit>? and region =? ");

Crs.setint (1, 5000);

Crs.SetString (2, "West");

Crs.execute ();

2. Jdbcrowset

JDBCROWSET is a component under Connected for ResultSet, which allows the ResultSet as a JavaBean component. At the same time, there is also two-way rolling, updated features of RowSet. It is actually equivalent to connecting the database connection, query, and the function of obtaining the results of the query result, saving a series of exception handles such as database connections, etc., greatly reducing the amount of procedures. If you are queried in a database in a database, you can use the following statement:

JDBCROWSET JRS = New JDBCROWSET (); Jrs.SETCOMMAND ("SELECT * from userinfo where type =?");

Jrs.SetURL ("JDBC: MyDriver: MyAttribute");

Jrs.setUsername ("Cervantes");

Jrs.SetPassword ("Sancho");

Jrs.setString (1, "Biography");

Jrs.execute ();

If you use the original JDBC database connection, you need to register the Dirver, get a connection from the database.

3. Webrowset

WebrowSet is inherited from the CachedRowSet, and its main function is to read and write the RESULTSET in the form of standard XML, thereby implementing data transfer between the Web. .

4. FilteredRowset

FilteredRowSet provides a filtering feature in a scalable way, in which rowset and data sources are in a disconnected state during the filtering process.

5. JoinRowset

JoinRowSet describes the relationship between multiple ROWSETs (in disconnected status), similar to the multi-table query mechanism of Join in SQL.

Author: jason

转载请注明原文地址:https://www.9cbs.com/read-18292.html

New Post(0)