Java统计数据库表中记录数

时间:2022-04-03 14:20:36
public static int count(String txyl_table) {// 获取用户数量
int i = 0;// Store_Information
Connection con = DB.getConnnection();
try {
Statement stmt = con.createStatement();
ResultSet rset = stmt.executeQuery("select count(*)as totalCount from "+ txyl_table);
if(rset.next()) {
i=rset .getInt("totalCount");
}
} catch (Exception e) {
System.err.println("你确定你没有输错表明么???");
e.printStackTrace();
} finally {
DB.closeConn(con);
}
System.out.println(i);
return i;
}