jsp分页

xiaoxiao2022-06-11  28

服务器端分页的实现:(参考:http://www.javaresearch.org/article/8893.htm)

 

1.如果是mysql,在查询sql的时候有一个limit选项,如以下的用法:

    select * from test limit 2,3;

 就是从第二条记录开始选择其后的三条记录

 

2.每次翻页都查询一次数据库,从ResultSet当中取出一页的数据:使用rs.last();rs.getRow()获得总计录条数,使用rs.absolute()定位到本页起始记录。这种方式在某些数据库(如oracle)的JDBC实现中差不多也是需要遍历所有记录,实验证明在记录数很大时速度非常慢。

 

3. 在oracle数据库中查询结果的行号使用伪列ROWNUM表示(从1开始)。例如 select * from employee where rownum<10 返回前10条记录。但因为rownum是在查询之后排序之前赋值 的,所以查询employee按birthday排序的第100到120条记录应该这么写:

        select * from (             select my_table.*, rownum as my_rownum from (                 select name, birthday from employee order by birthday             ) my_table where rownum <120         ) where my_rownum>=100

 

相关资源:jsp分页显示数据源代码
转载请注明原文地址: https://www.6miu.com/read-4931845.html

最新回复(0)