js| Paging
I have a detailed JSP paging program! (Oracle+jsp+apache)
A prerequisite
Hope that the latest record at the beginning of your table to create a query:
Table: MyTable
Query: Create or replace View as Mytable_view from MyTable ORDER by id DESC, preferably using serial number create sequence mytable_sequence from dynamic increase your Record ID number
Two 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= The number of records you display on each page;
int rowcount=0; Total number of records
while (Rscount
int PageCount; Total number of pages
int currpage; Current page
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 ();
%>
Here are the first few pages, etc.
<form name= "Sinfo" method= "post" action= "sbinfo_index.jsp?condition=<%=condition%>&type=<%=type% > "onsubmit=" return Testform (This) >
<%=currPage%> Page Total <%=pageCount%> page Total <%=rowCount%> bar
<%if (currpage>1) {%><a href= "sbinfo_index.jsp?condition=<%=condition%>&type=<%=type% > "> Home </a><%}%>
<%if (currpage>1) {%><a href= "sbinfo_index.jsp?page=<%=currpage-1%>&condition=<%= Condition%>&type=<%=type%> "> Prev </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%> "> End </a><%}%>
Skip 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>