Use the getHoldability() method of the Connection to get this property of a ResultSet object - Java JDBC

Java examples for JDBC:ResultSet

Description

Use the getHoldability() method of the Connection to get this 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 {// www .  ja  v  a  2 s  . c  om
      Connection conn = null;// JDBCUtil.getConnection();

      // Request a bidirectional change insensitive ResultSet with concurrency
      // as CONCUR_UPDATABLE and holdability of HOLD_CURSORS_OVER_COMMIT
      Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
          ResultSet.CONCUR_UPDATABLE, ResultSet.HOLD_CURSORS_OVER_COMMIT);

      String SQL = "your select statement goes here";

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

      // Let's see what type of holdability the JDBC driver returned
      int holdability = conn.getHoldability(); // Java 1.4 and later
      // int holdability = rs.getHoldability(); // Java 6 and later

      if (holdability == ResultSet.HOLD_CURSORS_OVER_COMMIT) {
        System.out.println("ResultSet is HOLD_CURSORS_OVER_COMMIT");
      } else if (holdability == ResultSet.CLOSE_CURSORS_AT_COMMIT) {
        System.out.println("ResultSet is CLOSE_CURSORS_AT_COMMIT");
      }

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

Result


Related Tutorials