Result set: the resulset object obtained after an SQL statement is executed by the statement instance. There are three types: Basic result set, rolling result set, and updatable result set. I. Basic result set 1. Features: there are only two retrieval methods: resultset. Next, getxxx2, and statement object creation method: ● statement: createstatement ()
● Preparedstatement statement: preparedcreatestatement (string SQL)
● Callablestatement statement: callablecreatestatement (string SQL) 3. Main method: ● the Boolean next () method moves the cursor to the next row. True is returned for valid data, note that the cursor position in the result returned by the query statement is before the first row.
● The getxxx (INT columnindex) method returns the value of the specified column in the current row by column number and converts it to the Java data type corresponding to XXX in the method. ● The getxxx (string columnname) method returns the value of the column specified in the current row by name and converts it to the Java data type corresponding to XXX in the method. Ii. scrollable result set 1. Features: Retrieval Method: provides a variety of methods for locating the cursor and freely scrolling the results in a centralized manner. Make up for the limitations that the basic result set can only be rolled before. 2 Statement statement object creation method: ● statement: createstatement (INT resultsettype, int reslutsetconcurrency)
● Preparestatement: preparestatement (string SQL, int resultsettype, int reslutsetconcurrency)
● Callablestatement: preparecall (string SQL, int resultsettype, int reslutsetconcurrency) resultsettype is type_scroll_insensitive type_scrol_sensitive
Constant |
Description |
Type_forward_only |
The result set cannot be rolled, which is equivalent to the basic result set. |
Type_scroll_insensitive |
The result set can be rolled, but when the result set is open, it is not sensitive to changes made in the underlying data table. |
Type_scrol_sensitive |
The result set can be rolled. When the result set is open, it is sensitive to changes made in the underlying data table. |
Concur_read_only |
The result set cannot be updated, so it provides the maximum possible concurrency level. |
Concur_updatable |
Results can be updated, but only limited concurrency levels can be provided. |
3. Main method: ● Boolean previous ()
● Boolean first ()
● Boolean last ()
● Void beforfirst () move the cursor to the first row
● Void afterlast () move the cursor after the last row
● Boolean relative (INT rows) moves the number of rows specified by the rows parameter relative to the current position of the cursor, positive and negative.
● Boolean absolute (INT row) moves the cursor to the data row specified by the row parameter. Rows is positive from the beginning of the result set, and the negative is backward from the end of the result set, before zero is moved to the first row. The method used to determine the current position of the cursor "● Boolean isbeforefirst (). If the cursor is located before the first row, true is returned.
● Boolean isafterlast () after the last row
● Boolean isfirst ()
● Boolean islast ()
Iii. updatable result set 1. features: the data in the result set can be updated and saved to the database. 2 Creation Method: ● statement: createstatement (INT resultsettype, int reslutsetconcurrency)
● Preparestatement: preparestatement (string SQL, int resultsettype, int reslutsetconcurrency)
● Callablestatement: preparecall (string SQL, int resultsettype, int reslutsetconcurrency) reslutsetconcurrency is concur_updatable 3. Method (to be continued)