I simply sorted out the pages, hoping to help beginners.

Source: Internet
Author: User
Tags rowcount

Preparations:
Create a table in Oracle:
Create Table mytable (ID int, name varchar (32 ))
/

Insert some values into mytable.

The testpage. jsp page program is as follows:

<! --
Simple paging example, demo
-->
<% @ Page import = "Java. util. *" %>
<% @ Page import = "Java. Lang. *" %>
<% @ Page import = "Java. Io. *" %>
<% @ Page import = "Java. SQL. *" %>
<% @ Page import = "java.net. *" %>
<% @ Page contenttype = "text/html; charset = GBK" %>

<%
String sconn = "JDBC: oracle: thin: @ host: 1521: orcl ";
Class. forname ("oracle. JDBC. Driver. oracledriver ");
Connection conn = drivermanager. getconnection (sconn, "user", "password ");
Statement stmt = conn. createstatement (resultset. type_scroll_sensitive, resultset. concur_read_only );
// Statement stmtcount = conn. createstatement (resultset. type_scroll_sensitive, resultset. concur_updatable );

Resultset rs1_stmt.exe cutequery ("select * From mytable ");
// String sqlcount = "select count (*) from mytable ";
// Resultset rscount=stmtcount.exe cutequery (sqlcount );

Int pagesize = 5; // 5 entries per page
Int rowcount = 0; // The total number of records.

Rs. Last ();
Rowcount = Rs. getrow ();

Int pagecount; // the total number of pages.
Int currpage = 0; // 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;
 
%>

Current page: <% = currpage %> <p>

<A href = "testpage. jsp? Page = 1 "> first page </a>

<%
If (currpage> 1 ){
%>
<A href = "testpage. jsp? Page = currPage-1 %> "> previous </a>
<%
}
%>
<%
If (currpage <pagecount ){
%>
<A href = "testpage. jsp? Page = <% = currpage + 1%> "> next page </a>
<%
}
%>
<A href = "testpage. jsp? Page = <% = pagecount %> "> last page </a> <p> <br> <HR>
Total <% = rowcount %> record pages: <% = currpage %>/<% = pagecount %> page <% = pagesize %>

& Lt; table width = "80%" & gt;
<%
If (currpage> 0 ){
Rs. Absolute (thepage + 1 );
While (n <pagesize &&! Rs. isafterlast ()){
Out. println ("<tr> <TD> ");
Out. println (Rs. getint (1) + "</TD> <TD> ");
Out. println (Rs. getstring (2) + "</TD> </tr> ");
Rs. Next ();
++ N;
}

}
%>

<%
Rs. Close ();
// Rscount. Close ();
Stmt. Close ();
// Stmtcount. Close ();
Conn. Close ();
%>

// Even if the test result is displayed on oracle8.1.6, the value of the Name field appears to be a hexadecimal byte string. However, there is no problem after oracle8.1.7. It may be that the degree of JDBC support is different.

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.