<%@ page language= "java" import= "java.util.*" pageencoding= "UTF-8"%>
<%@ page language= "java" import= "Java.sql.connection,java.sql.statement,java.sql.resultset"%>
<jsp:directive.page import= "Java.sql.DriverManager;" />
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" >
<body>
<%
Connection Con=null;
Loading Oracle jdbc Thin drivers
Class.forName ("Oracle.jdbc.driver.OracleDriver");
Oracle Thin JDBC URL
String url= "JDBC:ORACLE:THIN:@192.168.10.2:1521:ORA10";
con = drivermanager.getconnection (URL, "TRSPORTALV6", "TRSPORTALV6");
Statement stmt=con.createstatement ();
String sql= "SELECT COUNT (*) from Wcmmetatablexwlw_zzh";
ResultSet rs=stmt.executequery (SQL);
int jumppage=1;//Jump Page
int pagenum=1;//Current Page
int pagesize=3;//per page size
int countpage=0;//Total Pages
Total Records of int countrecord=0;//
Total number of records
if (Rs.next ()) {
Countrecord=rs.getint (1);
}
Total pages
if (countrecord% pageSize = = 0) {
Countpage = countrecord/pagesize;
}else{
Countpage = countrecord/pagesize+1;
}
String strpage=request.getparameter ("Pagenum");
String strjump=request.getparameter ("Jumppage");
if (strpage==null) {
pagenum=1;//if not, show the first page
}else{
Pagenum=integer.parseint (strpage);
if (pagenum<1) {
Pagenum=1;
}
}
To judge a jump page
if (strjump!=null) {
Pagenum=integer.parseint (Strjump);
if (pagenum<1) {
Pagenum=1;
}
if (pagenum>countpage) {
Pagenum=countpage;
}
}
int startpage= (pageNum-1) *pagesize+1;
int endpage= (pagenum) *pagesize;
This SQL statement is important and basically uses Oracle's rownum to implement pagination.
Sql= "SELECT * from" (select T.*,rownum r from Wcmmetatablexwlw_zzh T) where R between "+startpage+" and "+endpage+" ";
Rs=stmt.executequery (SQL);
while (Rs.next ()) {
%>
<table>
<tr><td><%=rs.getstring ("Cruser")%></td><td><%=rs.getstring ("CRTIME")%> </td></tr>
</table>
<%}%>
<table>
<form name= "name" action= "test.jsp" >
<tr>
<td> a total of <%=countRecord%> records </td>
<td> <a href= "test.jsp?pagenum=<%=pagenum%>" ><%=pageNum%></a> page </td>
<td> Total <%=countPage%> page </a></td>
<td><a href= "test.jsp?pagenum=0" > Home </a></td>
<td><%if (pagenum>1) {%><a href= "test.jsp?pagenum=<%=pagenum-1%>" > Prev </a><%}% ></td>
<td><%if (pagenum<countpage) {%><a href= "test.jsp?pagenum=<%=pagenum+1%>" > next page </a> <%}%></td>
<td><a href= "test.jsp?pagenum=<%=countpage%>" > Last </a></td>
<td> go to <input type= "text" name= "Jumppage" style= "width:15px" > Page <input type= "submit" value= "Jump" >< /TD>
</tr>
</form>
</table>
</body>