JDBC RowSetAn instance of RowSet is the Java bean component because it has properties and Java bean notification mechanism. It is the wrapper of ResultSet. A JDBC RowSet facilitates a mechanism to keep the data in tabular form. It happens to make the data more flexible as well as easier as compared to a ResultSet. The connection between the data source and the RowSet object is maintained throughout its life cycle. The RowSet supports development models that are component-based such as JavaBeans, with the standard set of properties and the mechanism of event notification. It was in the JDBC 2.0, the support for the RowSet was introduced using the optional packages. But the implementations were standardized for RowSet in the JDBC RowSet Implementations Specification (JSR-114) by the Sun Microsystems that is being present in the JDK (Java Development Kit) 5.0. The implementation classes of the RowSet interface are as follows:
Let's see how to create and execute RowSet. It is the new way to get the instance of JdbcRowSet since JDK 7.Advantage of RowSetThe advantages of using RowSet are given below:
Example of JdbcRowSetLet's see the simple example of JdbcRowSet without event handling code. FileName: RowSetExample.java The output is given below: Id: 55 Name: Om Bhim Salary: 70000 Id: 190 Name: abhi Salary: 40000 Id: 191 Name: umesh Salary: 50000 Example of JDBC RowSet with Event HandlingTo perform event handling with JdbcRowSet, you need to add the instance of RowSetListener in the addRowSetListener method of JdbcRowSet. The RowSetListener interface provides 3 method that must be implemented. They are as follows:
Let's write the code to retrieve the data and perform some additional tasks while the cursor is moved, the cursor is changed, or the rowset is changed. The event handling operation can't be performed using ResultSet, so it is preferred now. FileName: RowSetExample.java The output is as follows: Cursor Moved... Id: 55 Name: Om Bhim Salary: 70000 Cursor Moved... Id: 190 Name: abhi Salary: 40000 Cursor Moved... Id: 191 Name: umesh Salary: 50000 Cursor Moved... Next TopicJDBC New Features |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India