Web开发中用sql语句完成分页的高效率方法

王朝mssql·作者佚名  2008-05-19
窄屏简体版  字體: |||超大  

一、Jsp方法如下:

**********************

int curpage=1;//当前页

int page_record=20;//每页显示的记录数

//用下面的方法(sql查询完成,速度快)

curpage=Integer.parseInt(request.getParameter("page"));//获取传递的值,需要显示的页

ResultSet rs=cn.rsexecuteQuery("select top "+page_record+" * from tablename where id not in (select top "+(curpage*page_record)+" id from tablename order by id desc) order by id desc");

//本查询语句得到的是所要显示的1000页的20条记录,大致思路为――子查询排除需要显示的记录前的所有记录,父查询则对余下的记录进行降序排列

while(rs.next) {

out.println(rs.getInt("id").toString());

}

rs.close();

%

**********************

二、asp中的方法

*******************

dim curpage=1'当前页

dim page_record=20'每页显示的记录数

curpage=request("page")'获取传递的值,需要显示的页

……'连接数据库操作代码省略

rs.open "select top "+page_record+" * from tablename where id not in (select top "+(curpage*page_record)+" id from tablename order by id desc) order by id desc",conn,1,3

'本查询语句得到的是所要显示的1000页的20条记录,大致思路为――子查询排除需要显示的记录前的所有记录,父查询则对余下的记录进行降序排列

while not rs.eof

response.write rs("id")

rs.movenext

wend

rs.close

conn.close

%

*********************

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航