一个详细的j 分页程序(oracle j apache)

文章作者 100test 发表时间 2007:09:20 13:06:35
来源 100Test.Com百考试题网


一 前提
希望最新的纪录在开头
给你的表建立查询:表:mytable
查询:create or replace view as mytable_view from mytable order by id desc 其中,最好使用序列号create sequence mytable_sequence 来自动增加你的纪录id号

二 源程序
<%String sConn="你的连接"
Class.forName("oracle.jdbc.driver.OracleDriver").
Connection conn=DriverManager.getConnection(sConn,"你的用户名","密码").
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE).
Statement stmtcount=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE).

ResultSet rs=stmt.executeQuery("0select * from mytable_view").
String sqlcount="0select count(*) from mytable_view".
ResultSet rscount=stmtcount.executeQuery(sqlcount).

int pageSize=你的每页显示纪录数;
int rowCount=0. //总的记录数
while (rscount.next()){
rowCount=rscount.getInt(1).
}
int pageCount. //总的页数
int currPage. //当前页数
String strPage.
strPage=request.getParameter("page").
if (strPage==null){
currPage=1.
}
else{
currPage=Integer.parseInt(strPage).
if (currPage<1) currPage=1.
}
pageCount=(rowCount pageSize-1)/pageSize.
if (currPage>pageCount) currPage=pageCount.

int thepage=(currPage-1)*pageSize.
int n=0.
rs.absolute(thepage 1).
while (n<(pageSize)&.&.!rs.isAfterLast()){%>
你要罗列的纪录
<%
rs.next().
n .
}
%>
<%rs.close().
rscount.close().
stmt.close().
stmtcount.close().
conn.close().
%>

//下面是 第几页等

第<%=currPage%>页 共<%=pageCount%>页 共<%=rowCount%>条
<%if(currPage>1){%>首页<%}%>
<%if(currPage>1){%>上一页<%}%>
<%if(currPage下一页<%}%>
<%if(pageCount>1){%>尾页<%}%>
跳到




相关文章


利用JBuilder开发调试Servlet
利用JS在页面上动态生成直线
一个详细的j 分页程序(oracle j apache)
J 实现在浏览器关闭cookies情况下的会话管
时间显示控制四板斧
深入理解和改进J _Servlet会话管理机制
在Window T4.0上安装Apache Servlet j
澳大利亚华人论坛
考好网
日本华人论坛
华人移民留学论坛
英国华人论坛