用户名:
密 码: 记住
您当前的位置:首页 > 站长百科 > 服务器技术

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

时间:2015-01-18  来源:互联网  作者:佚名

  一、Jsp方法如下:
  **********************
  <%@ page language="java" import="java.util.*,java.sql.*" %>
  <%@ page contentType="text/html;charset=gb2312"%>
  
  <%
  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
  %>
  *********************

来顶一下
返回首页
返回首页
推荐资讯
【图文教程】dede织梦网站后台如何发表文章? 【图文教程】dede织梦网站后台如何对于新手站长可能不了解,dede织梦后台是如何发文章的。下面
2014站长圈十大事件:PR已死 移动算法兴起 2014站长圈十大事件:PR已死 移动算2014年即将过去,虽然站长圈相比过去几年稍显沉寂,但&ldquo
相关文章
    无相关信息
栏目更新
栏目热门