62,623
社区成员
发帖
与我相关
我的任务
分享/**
* @param table_name表名
* @return 某个表中的行数
* @throws Exception
*/
public int countObject(String table_name)
throws Exception{
Connection conn = null;
PreparedStatement pstm = null;
ResultSet rs = null;
int count = 0;
try{
conn = JdbcUtil.getConnection();
conn.setAutoCommit(false);
String sql = "select count(*) from ?";
pstm = conn.prepareStatement(sql);
pstm.set?(1,table_name);
rs = pstm.executeQuery();
if(rs.next()){
count = rs.getInt(1);
}
conn.commit();
}catch(Exception e){
conn.rollback();
throw e;
}finally{
JdbcUtil.close(rs, pstm, conn);
}
return count;
}
<a href="/middleEmp/backpage">上一页</a> <a href="/middleEmp/nextpage">下一页</a>