各位兄弟姐妹,这个程序再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;
}
其中:$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;
}
解决方案 »
- 帮我看看这道题,急求答案,解释。
- 关于垃圾回收器的问题
- 询问一下,如何在监听JButton后实现在另一个类中画图
- JFrame对象被disposal后调用setVisible(ture)怎么会有能显示,怎样才能彻底释放JFrame的资源
- 急!求助!Hibernate中遇到Could not synchronize database state with session问题
- 关于“==”与“equals”在Object类中的疑问
- IIS 安装不上求9 啊 急!!
- 软件自动更新的问题
- 数据库连接问题
- 如何用swing实现如下功能?
- 关于"Microsoft.XMLHTTP"的一个问题
- 帮忙看看这个程序??是什么问题??
mysql uses limit clause!
oracle uses row_num functionusing cursor is unefficient
你试试next循环计数
它有时总不能得到期望的结果(与数据库有关,与数据库返回类型表关,如表或光标)
这个好像都没有一个合理的解释或解决方案
要解决你的问题,可用
select count(*) recc form 表 where 条件
来先预查记录数
int counter = 0;
while(resultset.next())
counter++;来获得总记录数,或者也可以参考楼上的方法
last、first等方法经常会有问题