方法一:利用循环ResultSet的元素来获得ResultSet的总行数
示例代码如庆备下:
ResultSet rs;
int rowCount = 0;
while(rset.next()){
rowCount++;
}
方法二:利用sql语句中的count函弊差旁数获得ResultSet的总行数
示例代租橡码如下:
String sql = "select count(*) record_ from ( select * from yourtable t where t.column_ = 'value_' )";
ResultSet rs = ps.executeQuery(sql);
int rowCount = 0;
if(rs.next()){
rowCount=rs.getInt("record_");
}
PreparedStatement pstate = null;String sql = "SELECT * FROM CHE_GOOD WHERE TITLE LIKE ?";
pstate = con.prepareStatement(sql,
java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,
java.sql.ResultSet.CONCUR_READ_ONLY);
pstate.setString(1, "%"启枣毕 +greatwqs+ "%");
}
ResultSet result = pstate.executeQuery();
result.last();
int rowcount = result.getRow(); 这个是从项目里面截取下来的,主要是pstate = con.prepareStatement(sql,
java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,
java.sql.ResultSet.CONCUR_READ_ONLY);进行结果集的滚动. 还有什悄芹岩耐么问题再问..
select count(*) from tablename;返回的就是记录条数了,写到橘李你的封装类里去。ResultSet rs是没有直接喊陵取得行数的郑伍戚方法的