This example code, only the use of one of the commonly used methods of Oracle paging in the Web, does not involve MVC, code optimization and other things, master please drift over. Novice can refer to.
--------------------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------
<body>
Important code for Oracle paging, learn from Hanshunping Teacher's Java operations Oracle 12 speaking *********************************** <br>
<br>
<form action= "/testoraclefenye/index.jsp" >
<input type= "text" name= "PageSize" >
<input type= "Submit" name= "Submit" value= "Settings pagesize" >
<br/>
</form>
<table>
<tr>
<td> name </td>
<td> Salary </td>
</tr>
<%
Load Driver
Class.forName ("Oracle.jdbc.driver.OracleDriver");
Establish a connection
Connection conn = Drivermanager.getconnection (
"JDBC:ORACLE:THIN:@192.168.1.5:1521:BJSXT", "Scott", "Tiger");
Defining a result set
ResultSet rs = null;
Start with SQL Server from below
Statement sm = conn.createstatement ();
Initialize the number of record bars per page
int pageSize = 20;
String s_pagesize = Request.getparameter ("PageSize");
if (s_pagesize!=null &&! "". Equals (S_pagesize.trim ())) {
PageSize = Integer.parseint (s_pagesize);
}
How many pages are there in total, calculated
int pagecount = 0;
How many records are in total, and the query results
int rowCount = 0;
Current page
int currentpage = 1;
Number of record bars to initialize start and end
int start = 1;
int end = PageSize;
Get the total number of records
rs = Sm.executequery ("SELECT count (*) from EMP");
while (Rs.next ()) {
RowCount = Rs.getint (1);
if (rowcount%pagesize==0) {
PageCount = rowcount/pagesize;
} else {
PageCount = rowcount/pagesize+1;
}
}
Current page number
String s_currentpage = Request.getparameter ("CurrentPage");
if (s_currentpage!=null &&! "". Equals (S_currentpage.trim ())) {
CurrentPage = Integer.parseint (s_currentpage);
Start = (currentPage-1) *pagesize + 1;
end = Currentpage*pagesize;
}
Key code for paging
String fenyesql = "SELECT * from" (select a1.*, RowNum bieming from (SELECT * from EMP) A1 where rownum<= "+ End +") WH Ere bieming>= "+ start;
Out.println (fenyesql + "<br/>");
rs = Sm.executequery (fenyesql);
# #查询所有的员工 rs = sm.executequery ("SELECT * from emp");
while (Rs.next ()) {
Out.print ("<tr>");
Out.print ("<td>" + rs.getstring (2) + "</td>");
Out.print ("<td>" + rs.getstring (6) + "</td>");
Out.print ("</tr>");
}
Print Total Pages
for (int i=1; i<=pagecount; i++) {
Out.print ("<a href=" + basepath + "index.jsp?currentpage=" + i + "&pagesize=" + pageSize + "' >" + i + "</a> ; ");
}
Rs.close ();
Sm.close ();
Conn.close ();
%>
</table>
</body>
--------------------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------
Oracle paging on the Web home page