改变初始化Statement的时候设定结果集属性即可
当然首要条件是你使用的jdbc驱动支持滚动光标才行
Statement smt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
ResultSet.TYPE_SCROLL_SENSITIVE即设定结果集支持滚动光标且敏感

解决方案 »

  1.   

    conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
      

  2.   

    Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
    strCon = "jdbc:microsoft:sqlserver://ip:1433;DatabaseName=数据库"; //连接数据库 sqlCon = java.sql.DriverManager.getConnection(strCon,"用户","秘密"); 
    String QQuery = "{call Book_showre}";
    sqlStmt = sqlCon.prepareStatement(QQuery,java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,java.sql.ResultSet.CONCUR_READ_ONLY);
    //创建一个可以滚动的只读的SQL语句对象
    sqlCon.setReadOnly(true);
    boolean r=sqlCon.isReadOnly();
    //只读对象,加快速度sqlStmt.execute();sqlRst = sqlStmt.getResultSet();
    sqlRst.last();
      

  3.   

    Statement stmt = con.createStatement(
                                          ResultSet.TYPE_SCROLL_INSENSITIVE,
                                          ResultSet.CONCUR_UPDATABLE);
           ResultSet rs = stmt.executeQuery("SELECT a, b FROM TABLE2");
           // rs will be scrollable, will not show changes made by others,
           // and will be updatable
      

  4.   

    A default ResultSet object is not updatable and has a cursor that moves forward only. Thus, it is possible to iterate through it only once and only from the first row to the last row. New methods in the JDBC 2.0 API make it possible to produce ResultSet objects that are scrollable and/or updatable. The following code fragment, in which con is a valid Connection object, illustrates how to make a result set that is scrollable and insensitive to updates by others, and that is updatable. See ResultSet fields for other options. 
           Statement stmt = con.createStatement(
                                          ResultSet.TYPE_SCROLL_INSENSITIVE,
                                          ResultSet.CONCUR_UPDATABLE);
           ResultSet rs = stmt.executeQuery("SELECT a, b FROM TABLE2");
           // rs will be scrollable, will not show changes made by others,
           // and will be updatable