Scrollable ResultSet in JDBC example

A normal ResultSet object can only move in forward direction. But using the ResultSet.TYPE_SCROLL_SENSITIVE we can create Scrollable Resultset in JDBC.

What is Scrollable Resultset in JDBC

Scrollable Resultset is the resultset which can move forward or backward or move to any position when the ResultSet is open.

Types of Scrollable Resultset in JDBC

1. Sensitive ResultSet – Created using ResultSet.TYPE_SCROLL_SENSITIVE
A sensitive result set can see changes made to the database while the result set is open. This can be helpful to get the changes done to the table (columns or data) using the same resultSet.

2. Insensitive ResultSet – Created using ResultSet.TYPE_SCROLL_INSENSITIVE
An insensitive result set is not sensitive to changes made to the database while the result set is open. For any changes done to the table (columns or data) we will need a new resultSet.

Lets see an example of how Scrollable Resulset is used.

Example of Scrollable Resultset in JDBC

Output

Useful methods of ResultSet that can be used when Scrollable

Reference

1. ResultSet API