Web开发中一种用sql语句完成分页的高效率方法,以jsp/asp为例 (转)

Web开发中一种用sql语句完成分页的高效率方法,以jsp/asp为例 (转)[@more@]

一、JSP方法如下:
**********************
Java" import="java.util.*,java.sql.*" %>

SCOpe="page" class="myConnection.Conn" /><!--引用数据库操作的bean,自己完成,这里不再赘述--&gt
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中的方法
*******************
<Mailto:%@ LANGUAGE="vbscript'>%@ LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
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
%>
*********************
感谢阅读,希望本文对你有帮助


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10748419/viewspace-990778/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/10748419/viewspace-990778/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值