RowSet in Java JDBC

Last Updated : 6 Apr, 2026

RowSet is an advanced interface in Java provided in the javax.sql package, designed to handle tabular data in a more flexible and user-friendly way than ResultSet. It acts as a wrapper around ResultSet and supports features like scrolling, updating, and easy data manipulation .

  • Unlike ResultSet (in java.sql), RowSet is a JavaBean component with properties and event notification support.
  • Provides better flexibility with features like scrolling, updating, and disconnected operations (in some types).
  • Maintains a connection with the data source .
  • Stores data in tabular form, making it easier to manipulate and use.
resultset
RowSet

Note: RowSet is present in package javax.sql while ResultSet is present in package java.sql.   

RowSets are classified into five categories based on how they are implemented which are listed namely as below:

  • JdbcRowSet
  • CachedRowSet
  • WebRowSet
  • FilteredRowSet
  • JoinRowSet

Declaration of Jdbc RowSet interface

public interface JdbcRowSet extends RowSet, Joinable

In order to connect RowSet with the database, the RowSet interface provides methods for configuring Java bean properties which are depicted below:

void setURL(String url):
void setUserName(String user_name):
void setPassword(String password):

Steps to Create a JdbcRowSet

  1. Create a JdbcRowSet object using RowSetProvider.
  2. Set the database URL using setUrl().
  3. Provide username using setUsername().
  4. Set the password using setPassword().
  5. Define the SQL query using setCommand()

JdbcRowSet rowSet = RowSetProvider.newFactory().createJdbcRowSet();
// 1. Oracle database considered -> rowSet.setUrl("jdbc:oracle:thin:@localhost:1521:xe");
// 2. username is set customly as - root ->rowSet.setUsername("root");
// 3. Password is set customly as ->passrowSet.setPassword("pass");
// 4. Query -> rowSet.setCommand("select * from Students");

Example: Illustrate RowSet in JDBC

Assume we have a table named student in the database as:

+--------------+-------------+

| RollNo | Name | Marks |

+--------------+-------------+

| 1 | jack | 92 |

| 2 | jenny | 90 |

| 3 | mark | 80 |

| 4 | joe | 82 |

+--------------+-------------+

Implementing JdbcRowSet and retrieving the records

Java
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;

// Main class
class RowSetDemo {

    // Main driver method
    public static void main(String args[])
    {

        // Try block to check for exceptions
        try {

            // Loading and registering drivers
            Class.forName(
                "oracle.jdbc.driver.OracleDriver");

            // Creating a RowSet
            JdbcRowSetrowSet = RowSetProvider.newFactory()
                                   .createJdbcRowSet();

            // Setting URL, username, password
            rowSet.setUrl(
                "jdbc:oracle:thin:@localhost:1521:xe");
            rowSet.setUsername("root");
            rowSet.setPassword("pass");

            // Creating a query
            rowSet.setCommand("select * from Student");

            // Executing the query
            rowSet.execute();

            // Processing the results
            while (rowSet.next()) {

                // Print and display commands
                System.out.println("RollNo: "
                                   + rowSet.getInt(1));
                System.out.println("Name: "
                                   + rowSet.getString(2));
                System.out.println("Marks: "
                                   + rowSet.getString(3));
            }
        }

        // Catch block to handle the exceptions
        catch (Exception e) {

            // Print and display the exception along with
            // line number using printStackTrace() method
            e.printStackTrace();
        }
    }
}

Output:

RollNo: 1
Name: jack
Marks: 92
RollNo: 2
Name: jenny
Marks: 90
RollNo: 3
Name: mark
Marks: 80
RollNo: 4
Name: joe
Marks: 82

Comment