Enjoying this Java & JDBC tutorial?
Subscribe to Ram N Java on YouTubeIntroduction
In Java JDBC, JdbcRowSet is a connected RowSet that acts as a wrapper around a standard ResultSet. Unlike a basic ResultSet, a JdbcRowSet is scrollable and updatable by default, and it adheres to the JavaBeans component model.
In this guide, you will learn how to use JdbcRowSet to perform complete CRUD operations—inserting new rows, updating existing records, and deleting rows directly without writing explicit SQL INSERT, UPDATE, or DELETE statements.
1. Initialize and Configure JdbcRowSet
Create a JdbcRowSet instance using RowSetProvider and configure database connection parameters:
import javax.sql.rowset.JdbcRowSet;
import javax.sql.rowset.RowSetProvider;
public class JdbcRowSetDemo {
public static void main(String[] args) throws Exception {
JdbcRowSet rowSet = RowSetProvider.newFactory().createJdbcRowSet();
rowSet.setUrl("jdbc:mysql://localhost:3306/testdb");
rowSet.setUsername("root");
rowSet.setPassword("password");
rowSet.setCommand("SELECT id, name, salary FROM employee");
rowSet.execute();
// CRUD operations performed below...
}
}
2. Inserting Records with JdbcRowSet
Move the cursor to the insert row buffer, set the column values, and call insertRow():
// Move cursor to insert row buffer
rowSet.moveToInsertRow();
rowSet.updateInt("id", 105);
rowSet.updateString("name", "David");
rowSet.updateDouble("salary", 75000.0);
// Insert into the database
rowSet.insertRow();
rowSet.moveToCurrentRow();
System.out.println("Record inserted successfully!");
3. Updating and Deleting Records
Navigate to the targeted row using scrolling methods (such as absolute(), next(), or last()), update or delete the row:
// Updating a record
rowSet.absolute(1); // Navigate to first record
rowSet.updateDouble("salary", 85000.0);
rowSet.updateRow();
System.out.println("Record updated successfully!");
// Deleting a record
rowSet.last(); // Navigate to the last record
rowSet.deleteRow();
System.out.println("Record deleted successfully!");
// Close resource
rowSet.close();
Watch More Java Tutorials
Click here to watch in Youtube : https://www.youtube.com/watch?v=2VM0K-p_sUI
Click the below Image to Enlarge
![]() |
| JDBCRowSet Update- Insert-Delete Demo |
![]() |
| JDBCRowSet Update- Insert-Delete Demo |
![]() |
| JDBCRowSet Update- Insert-Delete Demo |


