sqlserver数据库分页问题,急、、、
各位兄弟姐妹,这个程序再oracle、mysql上执行没任何问题
其中:$where为条件,currentPage为当前页码,totalRecords为记录总数,numPerPage为页记录数
在oracle、mysql上可以返回正确的记录总数,但在sqlserver上返回记录总数为-3,是何原因啊?
应该如何去改正呢?谢谢各位了!
public static List query(String $where, Integer currentPage,
AIInteger totalRecords, int numPerPage) {
List templist = new ArrayList();
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try {
conn = MyDBHelper.getConnection();
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
rs = stmt.executeQuery(sql);
rs.last(); //1>处
totalRecords.setValue(rs.getRow()); //2>处
System.out.println("current page:= " + currentPage.toString() +
"; total:= " +
totalRecords + "; numPerPage:= " + numPerPage);
if (currentPage.intValue() > 1)
rs.absolute( (currentPage.intValue() - 1) * numPerPage);
else
rs.beforeFirst();
rs.setFetchSize(numPerPage);
while (rs.next()) {
、
、
、
tempList.add(temp);
numPerPage--;
}
rs.close();
stmt.close();
}
catch (SQLException ex) {
while (ex != null) {
System.out.println("Message :" + ex.getMessage());
}
}
catch (java.lang.Exception ex) {
ex.printStackTrace();
}
//释放一个连接到连接池
finally {
try {
conn.close();
}
catch (SQLException sqle) {
}
}
return tempList;
}