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.