最好的办法是利用sql语句进行分页,这样每次查询出的结果集中就只包含某页的数据内容。
sql语句分页,不同的数据库下的分页方案各不一样,下面是主流的三种数据库的分页sql:
oracle:
select * from
(select *,rownum as tempid from student ) t
where t.tempid between " + pageSize*(pageNumber-1) + " and " + pageSize*pageNumber
mysql:
select * from students limit " + pageSize*(pageNumber-1) + "," + pageSize;
sql server:
select top " + pageSize + " * from students where id not in +
(select top " + pageSize * (pageNumber-1) + id from students order by id) +
"order by id;