RowSet Interface in JDBC

RowSet Interface

  • A JDBC RowSet provides the way to store the data in tabular form. It makes the data more flexible and easier than a ResultSet.
  • The connection between RowSet object and data source is maintained throughout its life cycle.

Types of Implementation

There are five categories of RowSet based on their implemention:
1. JdbcRowSet
2. CachedRowSet
3. WebRowSet
4. FilteredRowSet
5. JoinRowSet

JdbcRowSet Interface

The JdbcRowSet is an extension of RowSet interface. It is a wrapper around the ResultSet object with some additional functionality.

Declaration of JdbcRowSet Interface
public interface JdbcRowSet
         extends RowSet, Joinable

Creating a JdbcRowSet Object
The JdbcRowSetImpl provides an implementation of the default constructor.

JdbcRowSetImpl jrs = new JdbcRowSetImpl();
jrs.setCommand("select * from Student where name = ?");
jrs.setString(1, "Surendra");

Example : Implementing JdbcRowSet & retrieving the records

import java.sql.Connection;  
import java.sql.DriverManager;  
import java.sql.ResultSet;  
import java.sql.Statement;  
import javax.sql.RowSetEvent;  
import javax.sql.RowSetListener;  
import javax.sql.rowset.JdbcRowSet;  
import javax.sql.rowset.RowSetProvider;
    public static void main(String args[])
            JdbcRowSetrowSet = RowSetProvider.newFactory().createJdbcRowSet();
            rowSet.setCommand("select * from Student");
                 System.out.println("RollNo: "+ rowSet.getInt(1));
                 System.out.println("Name: "+ rowSet.getString(2));
                 System.out.println("Course: "+ rowSet.getString(3));
        catch(Exception e)