一种高效的javabea分页For SqlServer

1/5/2008来源:Java教程人气:5773


  一种高效的javabea分页For SqlServer

<%@ page contentType="text/Html;charset=GB2312"%>
<%@ page import="ite.com.*,java.util.*"%>
<title>分页显示ForSQLServer使用Select分页</title>
<style type="text/CSS">
<!--
table { background-color: #000000;}
td {background-color: #FFFFFF;}
-->
</style>
<%
java.util.List rstlist=new java.util.ArrayList();
//数据库连接池初始化
DBManager dbm=new DBManager();
dbm.setDatasource("java:comp/env/jdbc/lerp");
int pagesize=10;
int pageno=0;
if (request.getParameter("pageno")==null){
pageno=1;
}else{
pageno=Integer.parseInt(request.getParameter("pageno"));
if(pageno<=0){
pageno=1;
}
}
//使用Select实现分页显示
//String sql=select top 每页显示记录数 * from tablename where id not in(select top 每页显示记录数*(显示当前页-1) id from tablename)
String sql="select top "+pagesize+" * from iokecontent where id not in(select top "+pagesize*(pageno-1)+" id from iokecontent where iokesort=54 order by id desc) and iokesort=54 order by id desc";
rstlist=dbm.queryByPage_SQL_Quick(sql);

out.PRintln("<table border=0 cellpadding=1 cellspacing=1 width=200>");
out.println("<tr><td>字段一</td><td>字段二</td></tr>");
for(int i=0;i<rstlist.size();i++){
out.println("<tr><td>"+((java.util.ArrayList)rstlist.get(i)).get(0)+"</td><td>"+((java.util.ArrayList)rstlist.get(i)).
get(2)+"</td></tr>");
}
out.println("</table>");

out.println("<a href=selectpage.jsp?pageno="+(pageno-1)+">上一页</a>");
out.println("<a href=selectpage.jsp?pageno="+(pageno+1)+">下一页</a>");

%>