123

public int  rowCount(String tablename){
	conn = DBConnection.getConn();
	int  num=0;
	try {
		st=conn.createStatement();
		rs= st.executeQuery("select count(*) from "+ tablename);
		rs.next();//结果集中,只有一条记录,其值为总记录数。
		num=rs.getInt(1);//获得总记录数。
		} catch (SQLException e) {
		e.printStackTrace();
		} finally {
		       DBConnection.close(conn, rs);
		}
	return num;
}
 

你可能感兴趣的:(123)