/* curpage 当前页,0表示第1页*/
@SuppressWarnings("unchecked")
public List execPage(String tablename,String whereSQL,String orderBySQL,int curpage,int pageSize) {
Connection con = null;
List list = new ArrayList();
try {
con = DBCon.getCon();
CallableStatement cstmt = con.prepareCall("{call dbo.sp_PagingOperation(?,?,?,?, ?,?,?,?)}");
cstmt.setString(1,tablename);
cstmt.setString(2,"*");
cstmt.setString(3,orderBySQL);
cstmt.setString(4,whereSQL);
cstmt.setInt(5,curpage);//当前第几页,首页为0
cstmt.setInt(6,pageSize);//每页显示条数
cstmt.setString(7,"");//分组依据,可以为空,不用填 group by
cstmt.registerOutParameter(8,Types.INTEGER);
cstmt.execute();
ResultSet rs = cstmt.getResultSet();
while (rs.next()) {
XuserDto dto = new XuserDto();
dto.setRid(rs.getInt("rowId"));
dto.setId(rs.getInt("id"));
dto.setAreaid(rs.getInt("areaid"));
dto.setBakint(rs.getInt("bakint"));
list.add(dto);
}
int counts = 0;
if (!cstmt.getMoreResults()) {
counts = cstmt.getInt(8);
}
XuserDto cou = new XuserDto();
cou.setCounts(counts);
list.add(cou);
rs.close();
cstmt.close();
}
catch (Exception e) {
e.printStackTrace();
}finally{try {con.close();} catch (Exception e) {e.printStackTrace();}}
return list;
}