试试这个:
<p>&lt;%@ page contentType=&quot;text/html;charset=8859_1&quot;
%&gt;</p>
<p>&lt;%<br>
//</font><font color="#000080" size="2">变量声明<br>
</font><font color="#000080" face="Verdana, Arial, Helvetica" size="2">java.sql.Connection
sqlCon;
//</font><font color="#000080" size="2">数据库连接对象<br>
</font><font color="#000080" face="Verdana, Arial, Helvetica" size="2">java.sql.Statement
sqlStmt;
//SQL</font><font color="#000080" size="2">语句对象<br>
</font><font color="#000080" face="Verdana, Arial, Helvetica" size="2">java.sql.ResultSet
sqlRst;
//</font><font color="#000080" size="2">结果集对象</font></p>
<font color="#000080" face="Verdana, Arial, Helvetica" size="2">
<p>java.lang.String strCon;
//</font><font color="#000080" size="2">数据库连接字符串<br>
</font><font color="#000080" face="Verdana, Arial, Helvetica" size="2">java.lang.String
strSQL;
//SQL</font><font color="#000080" size="2">语句</font></p>
<font color="#000080" face="Verdana, Arial, Helvetica" size="2">
<p>int intPageSize;
//</font><font color="#000080" size="2">一页显示的记录数<br>
</font><font color="#000080" face="Verdana, Arial, Helvetica" size="2">int intRowCount;
//</font><font
color="#000080" size="2">记录总数<br>
</font><font color="#000080" face="Verdana, Arial, Helvetica" size="2">int intPageCount;
//</font><font color="#000080" size="2">总页数<br>
</font><font color="#000080" face="Verdana, Arial, Helvetica" size="2">int intPage;
//</font><font
color="#000080" size="2">待显示页码<br>
</font><font color="#000080" face="Verdana, Arial, Helvetica" size="2">java.lang.String
strPage;</p>
<p>int i;</p>
<p>//</font><font color="#000080" size="2">设置一页显示的记录数<br>
</font><font color="#000080" face="Verdana, Arial, Helvetica" size="2">intPageSize = 2;</p>
<p>//</font><font color="#000080" size="2">取得待显示页码<br>
</font><font color="#000080" face="Verdana, Arial, Helvetica" size="2">strPage =
request.getParameter(&quot;page&quot
;<br>
if(strPage==null){//</font><font color="#000080" size="2">表明在</font><font
color="#000080" face="Verdana, Arial, Helvetica" size="2">QueryString</font><font
color="#000080" size="2">中没有</font><font color="#000080"
face="Verdana, Arial, Helvetica" size="2">page</font><font color="#000080" size="2">这一个参数,此时显示第一页数据<br>
</font><font color="#000080" face="Verdana, Arial, Helvetica" size="2">intPage = 1;<br>
}<br>
else
{//</font><font color="#000080" size="2">将字符串转换成整型<br>
</font><font color="#000080" face="Verdana, Arial, Helvetica" size="2">intPage =
java.lang.Integer.parseInt(strPage);<br>
if(intPage&lt;1) intPage = 1;<br>
}</p>
<p>//</font><font color="#000080" size="2">装载</font><font color="#000080"
face="Verdana, Arial, Helvetica" size="2">JDBC</font><font color="#000080" size="2">驱动程序<br>
</font><font color="#000080" face="Verdana, Arial, Helvetica" size="2">java.sql.DriverManager.registerDriver(new
oracle.jdbc.driver.OracleDriver());</p>
<p>//</font><font color="#000080" size="2">设置数据库连接字符串<br>
</font><font color="#000080" face="Verdana, Arial, Helvetica" size="2">strCon =
&quot;jdbc
racle:thin
linux:1521
ra4cweb&quot;;</p>
<p>//</font><font color="#000080" size="2">连接数据库<br>
</font><font color="#000080" face="Verdana, Arial, Helvetica" size="2">sqlCon =
java.sql.DriverManager.getConnection(strCon,&quot;hzq&quot;,&quot;hzq&quot
;</p>
<p>//</font><font color="#000080" size="2">创建一个可以滚动的只读的</font><font
color="#000080" face="Verdana, Arial, Helvetica" size="2">SQL</font><font color="#000080"
size="2">语句对象<br>
</font><font color="#000080" face="Verdana, Arial, Helvetica" size="2">sqlStmt =
sqlCon.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,java.sql.ResultSet.CONCUR_READ_ONLY);</p>
<p>//</font><font color="#000080" size="2">准备</font><font color="#000080"
face="Verdana, Arial, Helvetica" size="2">SQL</font><font color="#000080" size="2">语句<br>
</font><font color="#000080" face="Verdana, Arial, Helvetica" size="2">strSQL =
&quot;select name,age from test&quot;;</p>
<p>//</font><font color="#000080" size="2">执行</font><font color="#000080"
face="Verdana, Arial, Helvetica" size="2">SQL</font><font color="#000080" size="2">语句并获取结果集<br>
</font><font color="#000080" face="Verdana, Arial, Helvetica" size="2">sqlRst =
sqlStmt.executeQuery(strSQL);</p>
<p>//</font><font color="#000080" size="2">获取记录总数<br>
</font><font color="#000080" face="Verdana, Arial, Helvetica" size="2">sqlRst.last();<br>
intRowCount = sqlRst.getRow();</p>
<p>//</font><font color="#000080" size="2">记算总页数<br>
</font><font color="#000080" face="Verdana, Arial, Helvetica" size="2">intPageCount =
(intRowCount+intPageSize-1) / intPageSize;</p>
<p>//</font><font color="#000080" size="2">调整待显示的页码<br>
</font><font color="#000080" face="Verdana, Arial, Helvetica" size="2">if(intPage&gt;intPageCount)
intPage = intPageCount;<br>
%&gt;</p>
<p>&lt;html&gt;<br>
&lt;head&gt;<br>
&lt;meta http-equiv=&quot;Content-Type&quot;
content=&quot;text/html;
charset=gb2312&quot;&gt;<br>
&lt;title&gt;JSP</font><font color="#000080" size="2">数据库操作例程 </font><font
color="#000080" face="Verdana, Arial, Helvetica" size="2">- </font><font color="#000080"
size="2">数据分页显示 </font><font color="#000080" face="Verdana, Arial, Helvetica"
size="2">- JDBC 2.0 - Oracle&lt;/title&gt;<br>
&lt;/head&gt;</p>
<p>&lt;body&gt;</p>
<p>&lt;table border=&quot;1&quot;
cellspacing=&quot;0&quot;
cellpadding=&quot;0&quot;&gt;<br>
&lt;tr&gt;<br>
&lt;th&gt;</font><font color="#000080" size="2">姓名</font><font color="#000080"
face="Verdana, Arial, Helvetica" size="2">&lt;/th&gt;<br>
&lt;th&gt;</font><font color="#000080" size="2">年龄</font><font color="#000080"
face="Verdana, Arial, Helvetica" size="2">&lt;/th&gt;<br>
&lt;/tr&gt;</p>
<p>&lt;%<br>
if(intPageCount&gt;0){<br>
//</font><font color="#000080" size="2">将记录指针定位到待显示页的第一条记录上<br>
</font><font color="#000080" face="Verdana, Arial, Helvetica" size="2">sqlRst.absolute((intPage-1)
* intPageSize + 1);</p>
<p>//</font><font color="#000080" size="2">显示数据<br>
</font><font color="#000080" face="Verdana, Arial, Helvetica" size="2">i = 0;<br>
while(i&lt;intPageSize &amp;&amp;
!sqlRst.isAfterLast()){<br>
%&gt;<br>
&lt;tr&gt;<br>
&lt;td&gt;&lt;%=sqlRst.getString(1)%&gt;&lt;/td&gt;<br>
&lt;td&gt;&lt;%=sqlRst.getString(2)%&gt;&lt;/td&gt;<br>
&lt;/tr&gt;<br>
&lt;%<br>
sqlRst.next();<br>
i++;<br>
}<br>
}<br>
%&gt;</p>
<p>&lt;/table&gt;</p>
</font>
<p><font color="#000080" size="2">第</font><font color="#000080"
face="Verdana, Arial, Helvetica" size="2">&lt;%=intPage%&gt;</font><font color="#000080"
size="2">页</font><font color="#000080" face="Verdana, Arial, Helvetica" size="2">&amp;nbsp;&amp;nbsp;</font><font
color="#000080" size="2">共</font><font color="#000080" face="Verdana, Arial, Helvetica"
size="2">&lt;%=intPageCount%&gt;</font><font color="#000080" size="2">页</font><font
color="#000080" face="Verdana, Arial, Helvetica" size="2">&amp;nbsp;&amp;nbsp;&lt;%if(intPage&lt;intPageCount){%&gt;&lt;a
href=&quot;jdbc20-oracle.jsp?page=&lt;%=intPage+1%&gt;&quot;&gt;</font><font
color="#000080" size="2">下一页</font><font color="#000080"
face="Verdana, Arial, Helvetica" size="2">&lt;/a&gt;&lt;%}%&gt;&amp;nbsp;&amp;nbsp;&lt;%if(intPage&gt;1){%&gt;&lt;a
href=&quot;jdbc20-oracle.jsp?page=&lt;%=intPage-1%&gt;&quot;&gt;</font><font
color="#000080" size="2">上一页</font><font color="#000080"
face="Verdana, Arial, Helvetica" size="2">&lt;/a&gt;&lt;%}%&gt;</p>
<p>&lt;/body&gt;<br>
&lt;/html&gt;</p>
<p>&lt;%<br>
//</font><font color="#000080" size="2">关闭结果集<br>
</font><font color="#000080" face="Verdana, Arial, Helvetica" size="2">sqlRst.close();</p>
<p>//</font><font color="#000080" size="2">关闭</font><font color="#000080"
face="Verdana, Arial, Helvetica" size="2">SQL</font><font color="#000080" size="2">语句对象<br>
</font><font color="#000080" face="Verdana, Arial, Helvetica" size="2">sqlStmt.close();</p>
<p>//</font><font color="#000080" size="2">关闭数据库<br>
</font><font color="#000080" face="Verdana, Arial, Helvetica" size="2">sqlCon.close();<br>
%&gt;</font></p>