<%
@?page?contentType
=
"
text/html;charset=gb2312
"
?
%>
<%
@?page?errorPage
=
"
jsp1_error.jsp
"
??
import
=
"
java.util.*,?java.sql.*
"
?
%>
<%
//
String?sConn="jdbc:oracle:thin:@local:1521:test"?;
String?sConn
=
"
jdbc:odbc:test
"
;
//
String?cl="oracle.jdbc.driver.OracleDriver";
??String?sq2
=
"
sun.jdbc.odbc.JdbcOdbcDriver
"
;
Class.forName(sq2);
Connection?conn
=
DriverManager.getConnection(sConn,
"
sa
"
,
""
);
//
Connection?conn=DriverManager.getConnection(sConn,"admin","admin");
Statement?stmt
=
conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY?);
Statement?stmtcount
=
conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY?);

ResultSet?rs
=
stmt.executeQuery(
"
select?*?from?jobs
"
);
String?sqlcount
=
"
select?count(*)?as?count1?from?jobs
"
;
ResultSet?rscount
=
stmtcount.executeQuery(sqlcount);
//
rscount.last()?;
//
rscount.getRow()?;
int
?pageSize
=
3
;
//
一頁所包括的行數
int
?rowCount
=
0
;?
//
總的記錄數
while
(rscount.next())

??
{
???rowCount
=
rscount.getInt(
"
count1
"
);
//
取的表總的記錄數
??}
int
?pageCount;?
//
總的頁數
int
?currPage;?
//
當前頁數
String?strPage;
//
獲的上一頁或下一頁的頁碼值.
strPage
=
request.getParameter(
"
page
"
);
//
獲的上一頁或下一頁的頁碼值.
if
?(strPage
==
null
)
{
currPage
=
1
;
}
else
{
currPage
=
Integer.parseInt(strPage);
if
?(currPage
<
1
)
currPage
=
1
;
}
pageCount
=
(rowCount
+
pageSize
-
1
)
/
pageSize;
//
計算總的頁碼數
if
?(currPage
>
pageCount)
????currPage
=
pageCount;

int
?thepage
=
(currPage
-
1
)
*
pageSize;
//
計算當前的所在的行數
int
?n
=
1
;?
//
控制變量
if
(thepage
!=
0
)

?rs.absolute(thepage);
//
光標下移thepage+1?行
?
else
??rs.beforeFirst()?;
??
//
??rs.absolute(1);
%>
<
div?id
=
"
Layer1
"
?align
=
"
center
"
?style
=
?
"
background-color:?#999999
"
>
第
<%=
currPage
%>
頁?共
<%=
pageCount
%>
頁?共
<%=
rowCount
%>
條

<%
if
(currPage
>
1
)
{
%><
a?href
=
"
jsp1.jsp?page=1
"
>
首頁
</
a
><%
}
%>
<%
if
(currPage
>
1
)
{
%><
a?href
=
"
jsp1.jsp?page=<%=currPage-1%>
"
>
上一頁
</
a
><%
}
%>
<%
if
(currPage
<
pageCount)
{
%><
a?href
=
"
jsp1.jsp?page=<%=currPage+1%>
"
>
下一頁
</
a
><%
}
%>
<%
if
(pageCount
>
1
)
{
%><
a?href
=
"
jsp1.jsp?page=<%=pageCount%>
"
>
尾頁
</
a
><%
}
%>
?
<
table?border
=
1
?cellspacing
=
"
1
"
?cellpadding
=
"
1
"
>
???
<
tr
>
????
<
td
>
工號
<
td
>
????
<
td
>
描述
<
td
>
????
<
td
>
最小工資
<
td
>
????
<
td
>
最大工資
<
td
>
???
</
tr
>
<%
while
?(n
<=
3
?
&&
?rs.next())
//
當n<=一頁的行數時
{

%>
??
<
tr
>
????
<
td
><%=
rs.getInt(
1
)
%><
td
>
????
<
td
><%=
rs.getString(
2
)
%><
td
>
????
<
td
><%=
rs.getInt(
3
)
%><
td
>
????
<
td
><%=
rs.getInt(
4
)
%><
td
>
???
</
tr
>
??
<%
//
?if((thepage+n)==rowCount)?
//
如果當前行數大于總的行數跳出循環
//
????break;
??n
++
;
//
控制變量加一
}
%>
</
table
>
</
div
>
<%
rs.close();
rscount.close();
stmt.close();
stmtcount.close();
conn.close();
%>
下面來源:不詳
select top 10 b.* from (select top 20 主鍵字段,排序字段 from 表名 order by 排序字段 desc) a,表名 b where b.主鍵字段 = a.主鍵字段 order by a.排序字段
10 = 每頁記錄數
20 = (當前頁 + 1) * 每頁記錄數
1。用next()方法,
選從50-100行
int CurrentRow = 1;
int MinRow = 50;
int MaxRow = 100;
while(rs.next())
{
if (CurrentRow
{
CurrentRow++;
continue;
}
}
2.用absolute(int row)定位
先定位到50行,然后next();
3.用sql完成
SqlServer的語句:select top 50 * from (select top 100 * from sysobjects order by id) as a order by id desc
Oracle的語句:
select * from (select rownum r ,* from test) ss
where ss.r > 50 and ss.r <= 100;
測試速度 :
absolute()最慢;定位到10000條以后無法忍受!
next();前面幾條快,越往后越慢!
SqlServer語句,比next快很多,但也是越往后越慢!
Oracle語句,最快!幾乎不受條數影響!