我的一个具体的jsp分页程序!(oracle+jsp+apache)
一 前提
希望最新的纪录在开头给你的表建立查询
表mytable
查询create or replace view as mytable_view from mytable order by id desc 其中,最好使用序列号create sequence mytable_sequence 来自动增加你的纪录id号
二 源程序
%26lt;%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("select * from mytable_view");
String sqlcount="select count(*) from mytable_view";
ResultSet rscount=stmtcount.executeQuery(sqlcount);
int pageSize=你的每页显示纪录数;
int rowCount=0; //总的记录数
while (rscount
int pageCount; //总的页数
int currPage; //当前页数
String strPage;
strPage=request.getParameter("page");
if (strPage==null){
currPage=1;
}
else{
currPage=Integer.parseInt(strPage);
if (currPage%26lt;1) currPage=1;
}
pageCount=(rowCount+pageSize-1)/pageSize;
if (currPage%26gt;pageCount) currPage=pageCount;
int thepage=(currPage-1)*pageSize;
int n=0;
rs.absolute(thepage+1);
while (n%26lt;(pageSize)%26amp;%26amp;!rs
%%26gt;
%26lt;%rs.close();
rscount.close();
stmt.close();
stmtcount.close();
conn.close();
%%26gt;
//下面是 第几页等
%26lt;form name="sinfo" method="post" action="sbinfo_index.jsp?condition=%26lt;%=condition%%26gt;%26amp;type=%26lt;%=type%%26gt;" onSubmit="return testform(this)"%26gt;
第%26lt;%=currPage%%26gt;页 共%26lt;%=pageCount%%26gt;页 共%26lt;%=rowCount%%26gt;条
%26lt;%if(currPage%26gt;1){%%26gt;%26lt;a href="sbinfo_index.jsp?condition=%26lt;%=condition%%26gt;%26amp;type=%26lt;%=type%%26gt;"%26gt;首页%26lt;/a%26gt;%26lt;%}%%26gt;
%26lt;%if(currPage%26gt;1){%%26gt;%26lt;a href="sbinfo_index.jsp?page=%26lt;%=currPage-1%%26gt;%26amp;condition=%26lt;%=condition%%26gt;%26amp;type=%26lt;%=type%%26gt;"%26gt;上一页%26lt;/a%26gt;%26lt;%}%%26gt;
%26lt;%if(currPage%26lt;pageCount){%%26gt;%26lt;a href="sbinfo_index.jsp?page=%26lt;%=currPage+1%%26gt;%26amp;condition=%26lt;%=condition%%26gt;%26amp;type=%26lt;%=type%%26gt;"%26gt;下一页%26lt;/a%26gt;%26lt;%}%%26gt;
%26lt;%if(pageCount%26gt;1){%%26gt;%26lt;a href="sbinfo_index.jsp?page=%26lt;%=pageCount%%26gt;%26amp;condition=%26lt;%=condition%%26gt;%26amp;type=%26lt;%=type%%26gt;"%26gt;尾页%26lt;/a%26gt;%26lt;%}%%26gt;
跳到%26lt;input type="text" name="page" size="4" style="font-size:9px"%26gt;页
%26lt;input type="submit" name="submit" size="4" value="GO" style="font-size:9px"%26gt;
%26lt;/form%26gt;
完
