| The code is as follows: |
Copy code |
Statement stmt = conn. createStatement (ResultSet. TYPE_SCROLL_INSENSITIVE, ResultSet. CONCUR_READ_ONLY );
ResultSet rs = stmt.exe cuteQuery (SQL );
Rs. last ();
Int length = rs. getRow ();
|
The value of length is the number of rows. If you want to continue using the current dataset rs after obtaining the number of rows, run rs. beforeFirst () to return the cursor to the initial position.
The common format created by Statement is:
| The code is as follows: |
Copy code |
Statement stmt = con. createStatement (int type, int concurrency );
|
Parameter description:
Int type
The cursor of the ResultSet. TYPE_FORWORD_ONLY result set can only scroll down.
The cursor of the ResultSet. TYPE_SCROLL_INSENSITIVE result set can be moved up or down. When the database changes, the current result set remains unchanged.
ResultSet. TYPE_SCROLL_SENSITIVE returns a scrollable result set. When the database changes, the current result set changes synchronously.
Int concurrency
ResultSet. CONCUR_READ_ONLY cannot use the result set to update tables in the database.
ResultSet. CONCUR_UPDATETABLE can use the result set to update tables in the database.
After you use ResultSet re=stmt.exe cuteQuery (SQL statement) to query, you can use the following methods to obtain information: