记录数据库数据的数量问题

我的代码:
String sql = "select * from order_info where checkif='未审核'";
int num= 0;
PreparedStatement pstmt;
try {
pstmt = conn.prepareStatement(sql);
ResultSet rs = pstmt.executeQuery();
rs.afterLast();
num = rs.getRow();
rs.beforeFirst();
System.out.println(num);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return num;
为什么num里永远都是0呀,求解答

你只改sql当然不行,下面代码也要改的。rs.getRow只是获取当前行编号,和你的数量不沾边。以这位同学给你的sql,查出的是总数据量,你需要把num=rs.getRow()改成num=rs.getLong(1)

String sql = "select * from order_info where checkif='未审核'";
->
String sql = "select count(*) from order_info where checkif='未审核'";