【转自csdn】Web开发中一种用sql语句完成分页的高效率方法,以jsp/asp为例
2008-03-30 04:07
561 查看
一、Jsp方法如下:
**********************
<%@ page language="java" import="java.util.*,java.sql.*" %>
<%@ page contentType="text/html;charset=gb2312"%>
<jsp:useBean id="cn" scope="page" class="myConnection.Conn" /><!--引用数据库操作的bean,自己完成,这里不再赘述-->
<%
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中的方法
*******************
<%@ 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
%>
**********************
<%@ page language="java" import="java.util.*,java.sql.*" %>
<%@ page contentType="text/html;charset=gb2312"%>
<jsp:useBean id="cn" scope="page" class="myConnection.Conn" /><!--引用数据库操作的bean,自己完成,这里不再赘述-->
<%
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中的方法
*******************
<%@ 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
%>
相关文章推荐
- 通过asp.net 生成xml文件
- ASP.NET页面事件:顺序与回传详解
- Asp.net页面的生命周期之通俗理解 [zt]
- 跨站ASP Script攻击
- 问题:在手动刷新aspx页面时,出现“不重新发送信息,则无法刷新网页。请单击“重试”,或单击“取消”返回正查看的页。”
- ASP.NET:最新最全的ASP.NET学习资源大全(2008年03月01日更新)
- asp.net forums 缓存
- Asp.net页面的生命周期之通俗理解
- 实现asp在最近新闻上加闪动"news"标志
- Asp.net(C#)常用函数表
- ASP.NET状态管理之五:隐藏域、ViewState、ControlState
- ASP.NET MVC+LINQ开发一个图书销售站点
- ASP.NET MVC+LINQ开发一个图书销售站点(10):作者管理
- 系统开发之需求分析--心得体会(一)
- asp之FSO大全
- asp程序错误详细说明例表
- asp与asp.net
- ASP.NET MVC框架(第四部分): 处理表单编辑和提交场景
- ASP.NET MVC框架(第三部分): 把ViewData从控制器传到视图
- ASP.NET MVC框架(第二部分): URL路径选择