Oracle paging on the Web home page

Source: Internet
Author: User
Tags rowcount

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

Related Article

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.