Detailed JSP Paging

Source: Internet
Author: User
Tags query rowcount stmt
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>




Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.