<%@ 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">
<html>
<head>
</head>
<body>
<%
Connection con=null;
//載入 Oracle jdbc thin 驅動程式
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;//跳轉頁
int pageNum=1;//當前頁
int pageSize=3;//每頁大小
int countPage=0;//總頁數
int countRecord=0;//總記錄數
//總記錄數
if(rs.next()){
countRecord=rs.getInt(1);
}
//總頁數
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;//如果沒有則顯示第一頁
}else{
pageNum=Integer.parseInt(strPage);
if(pageNum<1){
pageNum=1;
}
}
//對跳轉頁進行判斷
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;
//這SQL語句很重要,基本上用了ORACLE的rownum來實現分頁的。
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>總共有<%=countRecord%>條記錄</td>
<td>第<a href="test.jsp?pageNum=<%=pageNum%>"><%=pageNum%></a>頁</td>
<td>總<%=countPage%>頁</a></td>
<td><a href="test.jsp?pageNum=0">首頁</a></td>
<td><%if(pageNum>1){%><a href="test.jsp?pageNum=<%=pageNum-1%>">上頁</a><%}%></td>
<td><%if(pageNum<countPage){%><a href="test.jsp?pageNum=<%=pageNum+1%>">下頁</a><%}%></td>
<td><a href="test.jsp?pageNum=<%=countPage%>">尾頁</a></td>
<td>轉到<input type="text" name="jumpPage" style="width: 15px">頁<input type="submit" value="跳轉" ></td>
</tr>
</form>
</table>
</body>
</html>