<%
@ 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语句,最快!几乎不受条数影响!