ResultSet.CONCUR_READ_ONLY : ResultSet « java.sql « Java by API






ResultSet.CONCUR_READ_ONLY

 

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

public class Main {
  public static void main(String[] args) throws Exception {
    Connection conn = getConnection();
    Statement st = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
        ResultSet.CONCUR_UPDATABLE);

    st.executeUpdate("create table survey (id int,name varchar(30));");
    st.executeUpdate("insert into survey (id,name ) values (1,'nameValue')");
    st.executeUpdate("insert into survey (id,name ) values (2,null)");
    st = conn.createStatement();
    ResultSet rs = st.executeQuery("SELECT * FROM survey");

    int rsConcurrency = rs.getConcurrency();
    if (rsConcurrency == java.sql.ResultSet.CONCUR_READ_ONLY) {
      System.out.println("java.sql.ResultSet.CONCUR_READ_ONLY");
    } else if (rsConcurrency == java.sql.ResultSet.CONCUR_UPDATABLE) {
      System.out.println("java.sql.ResultSet.CONCUR_UPDATABLE");
    } else {
      // it is an error

    }

    rs.close();
    st.close();
    conn.close();

  }

  private static Connection getConnection() throws Exception {
    Class.forName("org.hsqldb.jdbcDriver");
    String url = "jdbc:hsqldb:mem:data/tutorial";

    return DriverManager.getConnection(url, "sa", "");
  }
}

   
  








Related examples in the same category

1.ResultSet.CLOSE_CURSORS_AT_COMMIT
2.ResultSet.CONCUR_UPDATABLE
3.ResultSet.HOLD_CURSORS_OVER_COMMIT
4.ResultSet.TYPE_SCROLL_INSENSITIVE
5.ResultSet.TYPE_SCROLL_SENSITIVE
6.ResultSet: TYPE_FORWARD_ONLY
7.ResultSet: absolute(int row)
8.ResultSet: beforeFirst()
9.ResultSet: cancelRowUpdates()
10.ResultSet: close()
11.ResultSet: deleteRow()
12.ResultSet: first()
13.ResultSet.getAsciiStream(int columnIndex)
14.ResultSet: getBinaryStream(int columnIndex)
15.ResultSet: getBigDecimal(int columnIndex)
16.ResultSet: getBlob(int columnIndex)
17.ResultSet: getBlob(String colName)
18.ResultSet: getBytes(int columnIndex)
19.ResultSet: getClob(int columnIndex)
20.ResultSet: getConcurrency()
21.ResultSet: getDate(int columnIndex)
22.ResultSet: getDouble(String columnLabel)
23.ResultSet: getInt(int columnIndex)
24.ResultSet: getInt(String columnName)
25.ResultSet: getMetaData()
26.ResultSet: getObject(int columnIndex)
27.ResultSet: getObject(String columnLabel)
28.ResultSet: getRef(int columnIndex)
29.ResultSet: getRow()
30.ResultSet: getShort(String columnLabel)
31.ResultSet: getString(int columnIndex)
32.ResultSet: getString(String columnLabel)
33.ResultSet: getTime(int columnIndex)
34.ResultSet: getTimestamp(int columnIndex)
35.ResultSet: getType()
36.ResultSet: getWarnings()
37.ResultSet: insertRow()
38.ResultSet: isAfterLast()
39.ResultSet: isBeforeFirst()
40.ResultSet: isFirst()
41.ResultSet: last()
42.ResultSet: moveToInsertRow()
43.ResultSet: next()
44.ResultSet: previous()
45.ResultSet: refreshRow()
46.ResultSet: relative(int rows)
47.ResultSet: setFetchSize(int rows)
48.ResultSet: updateInt(String columnLabel, int x)
49.ResultSet: updateRow()
50.ResultSet: updateDouble(int columnIndex, double x)
51.ResultSet: updateString(String columnName, String x)
52.ResultSet: wasNull()