今天做了個基於jsp+oracle分頁的實現
package com
private static Connection connection = null;
static
{
try {
Class
connection = DriverManager
} catch (ClassNotFoundException e) {
// TODO Auto
e
} catch (SQLException e) {
// TODO Auto
e
}
}
protected static Connection getConnection()
{
return connection;
}
public int update(String sql)
{
//boolean flag = false;
int row =
Connection connection = DBManager
PreparedStatement statement = null;
try
{
statement = connection
row= statement
//
System
}
catch (SQLException e)
{
e
}
return row;
}
public ResultSet find(String sql)
{
Connection connection = getConnection()
ResultSet result = null;
PreparedStatement statement = null;
try
{
System
statement = connection
result = statement
} catch (SQLException e)
{
e
}
return result;
}}
<%@page import=
<base ;%=basePath%>
<title>用戶信息列表</title>
<meta http
<meta http
<meta http
<meta http
<meta http
<!
<link rel=
<body>
<table align=
<tr align=
<th>編號</th>
<th>用戶帳號</th>
<th>用戶姓名</th>
<th>用戶密碼</th>
<th>用戶信息</th>
</tr>
<%
int i;
int page_size=
int all_pages; //總頁數
int pages; //接受的頁碼變量
int cur_page=
int start_page; //本頁記錄開始
int count_row; //總記錄數
int end_page;//本頁記錄結束
String sql_row=
DBManager dbManager=new DBManager()
ResultSet count_rs=dbManager
count_rs
count_row=count_rs
all_pages=(int)Math
//判斷參數pages是否為空
if(request
pages=
}else{
pages= new Integer(request
}
//判斷當前頁
if(pages > all_pages || pages ==
cur_page =
} else {
cur_page = pages;
}
start_page=(cur_page
end_page=start_page+page_size;//本頁顯示的最後一條編號數
String sql=
ResultSet rsSet=dbManager
int t_row=
String color=
while(rsSet
if(t_row%
//讓表格更加好看雙數行數時顯示不同顏色
color=
}else{
color=
}
%>
<tr bgcolor=<%=color %》
<td><%=rsSet
<td><%=rsSet
<td><%=rsSet
<td><%=rsSet
<td><%=rsSet
</tr>
<%
t_row++;
}
%>
<tr>
<td colspan=
<%if(cur_page>
<a t;%=cur_page
<%
}
if(cur_page<all_pages){//不在最後一行時顯示下一頁
%>
<a t;%=cur_page+
<a t;%=all_pages%>
<%
}
%>
<% for (i=
<% if (i != pages) {%>
<a t;%= i %>
<% } else{%>
<%=i %>
<%} %>
<%}%>
共<%=all_pages %>頁
</td>
</tr>
</table> </body></html>
第二頁
第三頁
第四頁
注意
總頁數的求取是
sql語句是
例如
from
(
select rownum rn
from
(select *
from page order by id
)p where rownum<=
)where rn>
最後附上我的sql代碼
create table page(
id varchar
username varchar
password varchar
info varchar
constraints pk_id primary key(id))
from
(
select rownum rn
from
(select *
from page order by id
)p where rownum<=
)where rn>
from
(
select rownum rn
from
(select *
from page )p where rownum<=
)where rn>
From:http://tw.wingwit.com/Article/program/Java/hx/201311/26377.html