A detailed jsp paging program of mine! (oracle+jsp+apache)
The first premise is to create a query for your table with the latest records at the beginning:
Table: mytable
Query: create or replace view as mytable_view from mytable order by id desc. Among them, it is best to use the sequence number create sequence mytable_sequence to automatically increase your record id number.
Second source program
<%String sConn="your connection"
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn=DriverManager.getConnection(sConn,"your username","password");
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=Your number of records displayed on each page;
int rowCount=0; //Total number of records
while (rscount
int pageCount; //Total number of pages
int currPage; //Current page number
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
%>
<%rs.close();
rscount.close();
stmt.close();
stmtcount.close();
conn.close();
%>
//The following is the page etc.
<form name="sinfo" method="post" action="sbinfo_index.jsp?condition=<%=condition%>&type=<%=type%>" onSubmit="return testform(this)">
Page <%=currPage%>, total <%=pageCount%>, page total <%=rowCount%>
<%if(currPage>1){%><a href="sbinfo_index.jsp?condition=<%=condition%>&type=<%=type%>">Homepage</a><%}%>
<%if(currPage>1){%><a href="sbinfo_index.jsp?page=<%=currPage-1%>&condition=<%=condition%>&type=<%=type%>">Previous Page</a><%}%>
<%if(currPage<pageCount){%><a href="sbinfo_index.jsp?page=<%=currPage+1%>&condition=<%=condition%>&type=<%=type%>">Next Page</a><%}%>
<%if(pageCount>1){%><a href="sbinfo_index.jsp?page=<%=pageCount%>&condition=<%=condition%>&type=<%=type%>">Last page</ a><%}%>
Jump to <input type="text" name="page" size="4" style="font-size:9px"> page
<input type="submit" name="submit" size="4" value="GO" style="font-size:9px">
</form>
over