![]() |
VOOZH | about |
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 .
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:
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):
JdbcRowSetJdbcRowSet object using RowSetProvider.setUrl().setUsername().setPassword().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
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