前两种是基于数据库实现的,可降低程序的复杂度;后一种是基于JDBC2.0 应用程序实现,可以降低对数据库的消耗。各有利弊,根据应用来选。
方法一:
select t.* from
(select a.*,rownum rn from table a)t
where t.rn >40 and t.rn <= 50
方法二:
select t.* from table t where rownum <= 50
minus
select t.* from table t where rownum < 41
方法三:
//rs 为符合条件的所有记录
if (rs.next()) {
rs.last();
//总记录数
totalRowCount = rs.getRow();
//总页数
totalPageCount = (totalRowCount + perPageCount - 1)/ perPageCount;
//当前页数
if (currentPage > totalPageCount) {
currentPage = totalPageCount;
}
// 定位指针到分页的行记录上
rs.absolute((currentPage - 1) * perPageCount + 1);
// 处理结果集
ResultSetMetaData rsmd = rs.getMetaData();
int colCount = rsmd.getColumnCount();
for (int j = 0; j < perPageCount; j++) {
for (int i = 1; i <= colCount; i++) {
......
}
if (!rs.next()) {
break;
}
}
方法一:
select t.* from
(select a.*,rownum rn from table a)t
where t.rn >40 and t.rn <= 50
方法二:
select t.* from table t where rownum <= 50
minus
select t.* from table t where rownum < 41
方法三:
//rs 为符合条件的所有记录
if (rs.next()) {
rs.last();
//总记录数
totalRowCount = rs.getRow();
//总页数
totalPageCount = (totalRowCount + perPageCount - 1)/ perPageCount;
//当前页数
if (currentPage > totalPageCount) {
currentPage = totalPageCount;
}
// 定位指针到分页的行记录上
rs.absolute((currentPage - 1) * perPageCount + 1);
// 处理结果集
ResultSetMetaData rsmd = rs.getMetaData();
int colCount = rsmd.getColumnCount();
for (int j = 0; j < perPageCount; j++) {
for (int i = 1; i <= colCount; i++) {
......
}
if (!rs.next()) {
break;
}
}