Java如何获得ResultSet的总行数?

如题所述

取得ResultSet行数的方法主要有以下几种:1. 用ResultSet的getRow方法来取得总行数2. 利用循环ResultSet元素的方法取得总行数ResultSet rset = stmt.executeQuery(select * from table);int rowCount = 0;while(rset.next()) {�0�2 rowCount++;}3. 利用SQL语句来取得ResultSet的总行数ResultSet rset = stmt.executeQuery(select count(*) totalCount from yourTableName);int rowCount = 0;if(rset.next()) {�0�2 rowCount=rset .getInt(totalCount );}rowCount就是ResultSet的总行数。
温馨提示:内容为网友见解,仅供参考
无其他回答
相似回答