# What is TYPE_SCROLL_SENSITIVE ResultSet in JDBC?

JDBCJava 8ProgrammingObject Oriented Programming

This represents is a scrollable ResultSet i.e. the cursor moves in forward or backward directions. This type of ResultSet is sensitive to the changes that are made in the database i.e. the modifications done in the database are reflected in the ResultSet.

Which means if we have established a connection with a database using a JDBC program and retrieved a ResultSet holding all the records in a table named SampleTable. Meanwhile, if we have added some more records to the table (after retrieving the ResultSet), these recent changes will be reflected in the ResultSet object we previously obtained.

Following is an example which demonstrates how to create the TYPE_SCROLL_SENSITIVE result set.

### Example

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
public class ScrollSensitive {
public static void main(String[] args) throws Exception {
//Registering the Driver
DriverManager.registerDriver(new com.mysql.jdbc.Driver());
//Getting the connection
String url = "jdbc:mysql://localhost/testdb";
Connection con = DriverManager.getConnection(url, "root", "password");
//Creating a Statement object
Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
stmt.setFetchSize(1);
}
}
Published on 25-Mar-2019 15:25:51