How to test for the scrollability property of a ResultSet object - Java JDBC

Java examples for JDBC:ResultSet

Description

How to test for the scrollability property of a ResultSet object

Demo Code

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

public class Main {
  public static void main(String[] args) {
    try {//ww  w.j a  va 2s  .  c om
      Connection conn = null;// JDBCUtil.getConnection();

      // Request a bi-directional change insensitive ResultSet
      Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
          ResultSet.CONCUR_READ_ONLY);

      String SQL = "your select statement goes here";

      // Get a result set
      ResultSet rs = stmt.executeQuery(SQL);

      // Let's see what type of result set the JDBC driver returned
      int cursorType = rs.getType();

      if (cursorType == ResultSet.TYPE_FORWARD_ONLY) {
        System.out.println("ResultSet is TYPE_FORWARD_ONLY");
      } else if (cursorType == ResultSet.TYPE_SCROLL_SENSITIVE) {
        System.out.println("ResultSet is TYPE_SCROLL_SENSITIVE");
      } else if (cursorType == ResultSet.TYPE_SCROLL_INSENSITIVE) {
        System.out.println("ResultSet is TYPE_SCROLL_INSENSITIVE");
      }

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}

Result


Related Tutorials