Jsp+oracle for paging

Source: Internet
Author: User

Oracle:

CREATE TABLE Load
(
ID char ($) NOT NULL,
Title VARCHAR2 (+) NOT NULL,
Time VARCHAR2 (+) is not NULL,
DEF1 varchar2 (100),
Def2 VARCHAR2 (200),
DEF3 VARCHAR2 (300),
DEF4 VARCHAR2 (400),
DEF5 VARCHAR2 (500),
Dr Number (default 0),
TS char (+) default To_char (Sysdate, ' yyyy-mm-dd hh24:mi:ss ')
);

Jsp:

<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "
pageencoding= "UTF-8"%>
<% @page import= "java.sql.*"%>
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "HTTP://WWW.W3.ORG/TR/HTML4/LOOSE.DTD" >
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">
<title>insert title here</title>
<body>
<%! int pagesize=10;
int PageCount;
int showpage;
%>
<!--connect the database and fetch records from the database--
<%
Connection con;//declaring a database connection object
Statement sql;//declaring a database connection object
ResultSet rs;//declaring a database result set

try{
Class.forName ("Com.mysql.jdbc.Driver");
Class.forName ("Oracle.jdbc.driver.OracleDriver");
}catch (ClassNotFoundException e) {
}

try{
Con=drivermanager.getconnection ("Jdbc:mysql://127.0.0.1:3306/java", "Root", "1993");
Con=drivermanager.getconnection ("Jdbc:oracle:thin:@127.0.0.1:1521:arcl", "Mj_portal", "1");
Sql=con.createstatement (resultset.type_scroll_sensitive,resultset.concur_read_only);
Returning a scrollable result set
Rs=sql.executequery ("SELECT * from load");
Move the cursor to the last row
Rs.last ();
Gets the line number of the last row
int Recordcount=rs.getrow ();
Calculate the total number of pages after paging
Pagecount= (recordcount%pagesize==0)? (recordcount/pagesize):(recordcount/pagesize+1);

Get the number of pages a user wants to display:
String integer=request.getparameter ("ShowPage");
if (integer==null) {
integer= "1";
}
Try{showpage=integer.parseint (Integer);
}catch (NumberFormatException e) {
showpage=1;
}
if (showpage<=1) {
showpage=1;
}
if (Showpage>=pagecount) {
Showpage=pagecount;
}

If you want to display page showpage, then the value of the position to which the cursor should be moved is:
int position= (showPage-1) *pagesize+1;
Set the position of the cursor
Rs.absolute (position);
Use for loop to display the records that should be displayed on this page
for (int i=1;i<=pagesize;i++) {
%>
<div style= "width:100%;" >
<div style= "margin:15px;" >
<li style= "border-bottom:1px dashed #222; height:25px;list-style:none;" >
<a style= "float:left;width:5%;" ><%=rs.getstring ("id")%></a>
<a style= "float:left;width:88%;" ><%=rs.getstring ("title")%></a>
<a style= "margin-right:5px;width:7%;" ><%=rs.getstring ("Time")%></a>
</li>
</div>
</div>
<%
Rs.next ();
}
Rs.close ();
Con.close ();
}
catch (Exception e) {
E.printstacktrace ();}
%>
<br>
<div style= "margin-left:15%;" >
<div style= "margin-top:-18px;margin-left:130px" >
<a href= "list.jsp?showpage=1" > Home </a>
<a href= "list.jsp?showpage=<%=showpage-1%>" > Prev </a>
<%//Display the number of each page according to the value of PageCount and append the corresponding hyperlink
for (int i=1;i<=pagecount;i++) {
%>

<%}
%>
<a href= "List.jsp?showpage=<%=showpage+1%>" > Next </a>
<a href= "list.jsp?showpage=<%=pagecount%>" > End </a>
<a> Section <%=showpage%> page </a>
<a> Total <%=pagecount%> page </a>
</div>
<!--submit the number of pages the user wants to display through the form-
<form action= "" method= "Get" style= "margin-top:-18px;margin-left:420px" >
Jump to section <input type= "text" name= "ShowPage" size= "4" > page
<input type= "Submit" name= "submit" value= "Jump" >
</form>
</div>

</body>

Jsp+oracle for paging

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.