我正在尝试获取我从查询中获取的 ResultSet 中的数字,如下面的代码所示。查询检索数字 5。如何从 ResultSet 中获取此数字?
代码:
String sql_count_stop = "select count(*) FROM behaviour where mac = ? ";
PreparedStatement preparedCount = con.prepareStatement(sql_count_stop);
preparedCount.setString(1, macD);
ResultSet rsCount = preparedCount.executeQuery();
while(rsCount.next()){
}
最佳答案
您可以将查询修改为
"SELECT count(*) AS totalCount FROM behaviour WHERE mac = ? ";
然后使用,
macId= rsCount.getInt("totalCount");
关于java - 从 ResultSet 中获取行数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31035511/