The resultset API in JDBC does not directly obtain the number of records. Here we will introduce several methods: Method 1: Use the getrow method of resultset to obtain the total number of rows of resultset. Java code: resultset RS; RS. last (); // move to the last row int rowcount = Rs. getrow (); // obtain the current row number, that is, the number of records Rs. beforefirst (); // if you want to use a result set, move the pointer to the initialization position. Method 2: Use the element of the cyclic resultset to obtain the total number of rows of the resultset. Java code: resultset RS; int rowcount = 0; while (rset. next () {rowcount ++;} method 3: Use the count function in the SQL statement to obtain the total number of rows in the resultset. Java code string SQL = "select count (*) record _ from (select * From yourtable t where T. column _ = 'value _ ') "; resultset rs = ps.exe cutequery (SQL); int rowcount = 0; If (RS. next () {rowcount = Rs. getint ("record _");}
Resultset rs = stmt.exe cutequery ("select count (*) from table"); RS. Next (); int I = Rs. getint (1 );