Oracle homepage on the Web

Source: Internet
Author: User

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 -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

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.