ResultSet rs = ps.executeQuery();
int rowcount = 0;
if (rs.last()) {
rowcount = rs.getRow();
rs.beforeFirst(); // not rs.first() because the rs.next() below will move on, missing the first element
}
while (rs.next()) {
// do your standard per row stuff
}
本文介绍了一种使用Java JDBC从数据库查询结果集中获取行数的方法。通过执行查询并将结果存储在ResultSet对象中,可以利用last()和getRow()方法确定总行数,并使用beforeFirst()确保不会遗漏第一行数据。
255





