Oracle homepage on the Web
The code in this example only describes how to use common Oracle paging methods on the Web. It does not involve MVC, code optimization, and so on. For more information, see.
Zookeeper -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
<Body>
* ************************************ Oracle Paging important code, I learned how to operate Oracle in Java ***************************** *********** <br>
<Br>
<Form action = "/TestOracleFenye/index. jsp">
<Input type = "text" name = "pageSize">
<Input type = "submit" name = "submit" value = "set pageSize">
<Br/>
</Form>
<Table>
<Tr>
<Td> name </td>
<Td> salary </td>
</Tr>
<%
// Load the 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 ");
// Define the result set
ResultSet rs = null;
// The same as SqlServer from below
Statement sm = conn. createStatement ();
// Initialize the number of records on each page
Int pageSize = 20;
String s_PageSize = request. getParameter ("pageSize ");
If (s_PageSize! = Null &&! "". Equals (s_PageSize.trim ())){
PageSize = Integer. parseInt (s_PageSize );
}
// Calculate the total number of pages
Int pageCount = 0;
// Query the total number of records
Int rowCount = 0;
// Current page
Int currentPage = 1;
// Number of records whose initialization starts and ends
Int start = 1;
Int end = pageSize;
// Obtain the total number of records
Rs = sm.exe cuteQuery ("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 + ") where bieming> =" + start;
Out. println (fenyeSql + "<br/> ");
Rs = sm.exe cuteQuery (fenyeSql );
// ## Query all employees rs = sm.exe cuteQuery ("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 the total number of 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>
Zookeeper -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------