如何获取数据库中数据的数量
我的代码:Stringsql="select*fromorder_infowherecheckif='未审核'";intnum=0;PreparedStatementps...
我的代码:
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呀,求解答 展开
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呀,求解答 展开
展开全部
这样试一试:
String sql = "select count(*) from order_info where checkif='未审核'";
int num= 0;
PreparedStatement pstmt;
try {
pstmt = conn.prepareStatement(sql);
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
num = rs.getInt(0);
}
System.out.println(num);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return num;
追问
报错
追答
抱什么错?发一些截图。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询