Share on Google+Share on Google+

JDBC ResultSet Scroll Sensitive Type Example

Through this ResultSet type the cursor can move in any direction.

JDBC ResultSet Scroll Sensitive Type Example:

Through this ResultSet type the cursor can move in any direction. It is sensitive which means result set that reflect changes made.

The following syntax are use for initialize the statement object to create a Scroll-Sensitive, read only ResultSet object.

Statement stmt = connection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);

package ResultSet;
import java.sql.*;

public class ScrollableResultSet {

  public static void main(String [] args) {
    Connection connection = null;
      String url = "jdbc:mysql://localhost:3306/";
      String dbName = "roseindia_jdbc_tutorials";
      String driverName = "com.mysql.jdbc.Driver";
      String userName = "root";
      String password = "root";
      try {
        connection = DriverManager.getConnection(url+dbName, userName, password);
           Statement stmt = connection.createStatement(
           stmt.executeUpdate("insert into user (user_id, user_name ) values (6,'Deepak')");   
        ResultSet res = stmt.executeQuery("SELECT * FROM user");
        if (res.getType() == ResultSet.TYPE_SCROLL_SENSITIVE) {
          System.out.println("ResultSet TYPE_SCROLL_SENSITIVE.");
        else {
          System.out.println("ResultSet scrollable.");
        while (!res.isBeforeFirst()){
          System.out.print("User id :" + res.getInt("user_id"" ");
            System.out.println("User Name :" + res.getString("user_name"));
      catch (Exception e) {
        System.err.println("Exception: "+ e.getMessage());

If you will run this example with the help of eclipse IDE and see the output that display message related to the ResultSet type.

Program output:

The database table before execute this example is:

The eclipse console output after execute this program is:

The database table after execution of this example:

Download source code


Posted on: October 22, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.