JDBC introduction (7)

xiaoxiao2021-03-06  38

ResultSetcursor

Establishing Statement or PreparedStatement in the previous section, Createment () and preparedStatement () used in the connection, which can only use the next () method to get the query result with the next () method. Specifying ResultSet Type when establishing a Statement component, the specified parameter has ResultSet.Type_forward_only, resultSet.Type_Scroll_insensitive with ResultSet.Type_Scroll_Sensitive, in the case of not specified, the default is the first. Also only using next () to access records. ResultSet controls a cursor pointing to the current data line. Initial, the cursor is positioned before the first line. Use the 'NEXT' method to move the cursor to the next line. Specify a second or third article, you can use the resultset's afterlast (), previous (), absolute (), relative (), etc ..ResultSet.Type_scroll_insensitive and resultSet.Type_Scroll_Sensitive Differences Different from whether it can get the resultSet change Information, and we must also specify ResultSetConcurrency, there is RESULTSET.CONCUR_READ_ONLY and the resultSet.concur_updata two parameters can be set, the former can only read the result of ResultSet, the latter means to use the ResultSet to operate the database .createStatement () does not give parameters , the default is ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY. the following example shows how to control the reading ResultSet cursor when establishing Statement, and ResultSet.CONCUR_READ_ONLY to use ResultSet.TYPE_SCROLL_INSENSITIVE .Statement stmt = conn.createStatement (ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.concur_read_only); ResultSet Result = Stmt.executeQuery; Result.AFTERLAST (); // Move ResultSet's read cursor to the last record after WHILE (Result.Previous ()) {system .out.getstring ("name") "/ t"); system.out.print (Result.getstring ("email") "/ t"); system.out.print (Result.getstring ("Subject") "/ t"); system.out.print (Result.getstring ("Time") "/ t"); system.out.println (Result .getstring ("MEMO") "/ t");} stmt.close (); conn.close (); can also use the absolute () method to specify the location of the query record .Absolute (-1), if there is The 100 results records, which represents the last record. Beforefirst (), move the cursor to the first record, first () moves to the first record, Last () moves to the last record.

转载请注明原文地址:https://www.9cbs.com/read-58483.html

New Post(0)