给你个分页的例子,改改数据库连接和sql语句就行了。<%@ page contentType="text/html;charset=8859_1" %> <% 
//变量声明 
java.sql.Connection sqlCon; //数据库连接对象 
java.sql.Statement sqlStmt; //SQL语句对象 
java.sql.ResultSet sqlRst; //结果集对象 java.lang.String strCon; //数据库连接字符串 
java.lang.String strSQL; //SQL语句 int intPageSize; //一页显示的记录数 
int intRowCount; //记录总数 
int intPageCount; //总页数 
int intPage; //待显示页码 
java.lang.String strPage; int i; //设置一页显示的记录数 
intPageSize = 2; //取得待显示页码 
strPage = request.getParameter("page"); 
if(strPage==null){//表明在QueryString中没有page这一个参数,此时显示第一页数据 
intPage = 1; 

else{//将字符串转换成整型 
intPage = java.lang.Integer.parseInt(strPage); 
if(intPage<1) intPage = 1; 
} //装载JDBC驱动程序 
java.sql.DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver()); //设置数据库连接字符串 
strCon = "jdbc:oracle:thin:@linux:1521:ora4cweb"; //连接数据库 
sqlCon = java.sql.DriverManager.getConnection(strCon,"hzq","hzq"); //创建一个可以滚动的只读的SQL语句对象 
sqlStmt = sqlCon.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,java.sql.ResultSet.CONCUR_READ_ONLY); //准备SQL语句 
strSQL = "select name,age from test"; //执行SQL语句并获取结果集 
sqlRst = sqlStmt.executeQuery(strSQL); //获取记录总数 
sqlRst.last(); 
intRowCount = sqlRst.getRow(); //记算总页数 
intPageCount = (intRowCount+intPageSize-1) / intPageSize; //调整待显示的页码 
if(intPage>intPageCount) intPage = intPageCount; 
%> <html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"> 
<title>JSP数据库操作例程 - 数据分页显示 - JDBC 2.0 - Oracle</title> 
</head> <body> <table border="1" cellspacing="0" cellpadding="0"> 
<tr> 
<th>姓名</th> 
<th>年龄</th> 
</tr> <% 
if(intPageCount>0){ 
//将记录指针定位到待显示页的第一条记录上 
sqlRst.absolute((intPage-1) * intPageSize + 1); //显示数据 
i = 0; 
while(i<intPageSize && !sqlRst.isAfterLast()){ 
%> 
<tr> 
<td><%=sqlRst.getString(1)%></td> 
<td><%=sqlRst.getString(2)%></td> 
</tr> 
<% 
sqlRst.next(); 
i++; 


%> </table> 第<%=intPage%>页   共<%=intPageCount%>页   <%if(intPage<intPageCount){%><a href="jdbc20-oracle.jsp?page=<%=intPage+1%>">下一页</a><%}%>   <%if(intPage>1){%><a href="jdbc20-oracle.jsp?page=<%=intPage-1%>">上一页</a><%}%> </body> 
</html> <% 
//关闭结果集 
sqlRst.close(); //关闭SQL语句对象 
sqlStmt.close(); //关闭数据库 
sqlCon.close(); 
%> 

解决方案 »

  1.   

    <%
    int pageno;
    int pagesize;
    int curpagesize = 0;
    String infViewer = WebUtil.getConfig("infViewer","WebINI")+"";
    String tmppgno = request.getParameter("pgno")+"";
    int tmpid = Integer.parseInt(request.getParameter("classID")+"");if (tmppgno.length()==0 || tmppgno.equalsIgnoreCase("null"))
    {
        pageno = 1;
    }
    else
    {
        pageno = Integer.parseInt(tmppgno);
    }tmppgno = request.getParameter("pageSize")+"";
    if (tmppgno.length()==0 || tmppgno.equalsIgnoreCase("null"))
    {
        pagesize = Integer.parseInt(WebUtil.getConfig("pageSize","WebINI"));
    }
    else
    {
        pagesize = Integer.parseInt(tmppgno);
    }
    %>
      <ECSN:Info prmtclassID="classID" filter="parentID=-1" type="infoList" loop="false" tagName="hbc" pageSize="<%=pagesize%>" pageIndex="<%=pageno%>" order="CreateTime" sort="true" id="infolist1">
        </ECSN:Info>
          <table height=45 cellspacing=0 cellpadding=0 width="100%" align=center border=0>
            <tbody>
         <ECSN:Info sourceTag="hbc" type="infoList" >
            <tr id=infotr>
              <td width="6%" height=18>
                <div align=center>
                  <img height=5 src="images/bluedot.gif" width=5>
                </div>
              </td>
              <td width="76%" height=0>
          &nbsp;
        <span id=stockdate>
          <a href="<%=infViewer%>?infoID=<ECSN:Info detail="ID"/>&classID=<ECSN:Info detail="classID"/>" target="_blank">
            <ECSN:Info detail="Title" titleLength="32"/>
          </a>
        </span>
      </td>
      <%curpagesize = curpagesize + 1;%>
         <td width="18%" height=0>
        <span id=infodate><ECSN:Info detail="CreateTime" dataFormat="yyyy/MM/dd" /></span>
      </td>
       </tr>
    </ECSN:Info><%  
        ObjSet objset = infolist1.getValueSet();
    int infoPageCount = objset.getPageCount();
        int pgcnt=objset.getTotalCount();
        int _mod;
    int pgfrom=1;
    int pgend=0;
    int lastpage=(pgcnt/pagesize)+1;
    pgfrom=pgfrom+pagesize*(infoPageCount-1);
    _mod=pgcnt%pagesize;
    if(infoPageCount==lastpage)
        pgend=pgfrom+_mod-1;
    else
        pgend=pgfrom+pagesize-1;
        if((_mod!=0)&&(pageno==lastpage)){
                for(int i=1;i<=pagesize-_mod;i++){
    %>
           <tr>
              <td width="6%" height=18>
    &nbsp;
              </td>
              <td width="76%" height=0>   </td>

         <td width="18%" height=0>
        
      </td>
       </tr>
        <%
    }
                    }
    if(infoPageCount==0){
    for(int i=1;i<=pagesize-_mod;i++){
    %>
           <tr>
              <td width="6%" height=18>
    &nbsp;
              </td>
              <td width="76%" height=0>   </td>

         <td width="18%" height=0>
        
      </td>
       </tr>
        <%
    }
                    }
    %>
       <%
       /**显示页面按页号进行导航  edit by zhengxiao
        * InfoTag.getValueSet().getPageCount() 返回总页数
        * InfoTag.getValueSet().getPageIndex() 返回当前页号
       */
       %>
       <%   
       if (pageno <1)
       {
           pageno=1;
       }
       else
       {
           if (pageno >infoPageCount)
           {
               pageno=infoPageCount;
           }
       }
       %>
       <tr>
         <td height="1">&nbsp;</td>
            </tr>
            <tr>
              <td colspan=3 height=30>
                <table cellspacing=3 cellpadding=0 width="100%" border=0>
                  <tbody>
                  <tr bgcolor=#e6e6e6>
                    <td width="25%">
                      <div align=right>
                         共
                              <span id=recordTotalCount>
                              <font  color=#ff0000>
                                  <ECSN:Info sourceTag="hbc" type="objsetDetail" detail="totalCount"/></font>                          </span>
                         条&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
                      </div>
                    </td>
                    <td width="33%">
                      <div align=center>
                        <a id=firstpage>                        <a href="./?classID=<%=tmpid%>&pgno=1&parentID=<%=request.getParameter("parentID") %>&order=<%=request.getParameter("order")%>&pageSize=<%=pagesize %>">首页 </a>                    </a>
                        <%
                          if (pageno >= 2)
                          {
                        %>
                        <a href="./?classID=<%=tmpid%>&pgno=<%=pageno-1%>&parentID=<%=request.getParameter("parentID") %>&order=<%=request.getParameter("order")%>&pageSize=<%=pagesize %>">
                          &nbsp;上页
                        </a>
                        <%
                          }
                          else
                          {
                        %>
                          &nbsp;上页
                        <%
                          }
                          if (pageno == infoPageCount)
                          {
                        %>
                        &nbsp;下页
                        <%
                          }
                          else
                          {
                        %>
                        <a href="./?classID=<%=tmpid%>&pgno=<%=pageno+1%>&parentID=<%=request.getParameter("parentID") %>&order=<%=request.getParameter("order") %>&pageSize=<%=pagesize %>">
                          &nbsp;下页
                        </a>
                        <%
                           }
                        %>
                        <a href="./?classID=<%=tmpid%>&pgno=<%=infoPageCount%>&parentID=<%=request.getParameter("parentID") %>&order=<%=request.getParameter("order")%>&pageSize=<%=pagesize %>">
                           &nbsp;尾页
                        </a>
                      </div>
                    </td>
                    <td width="12%" bgcolor=#e6e6e6>
                      <div align=center>                       第
                           <span id=pageIndexNum>
                           <%=pageno%>
                           </span>
                           /
                           <span id=pageTotalCount>
                           <ECSN:Info sourceTag="hbc" type="objsetDetail" detail="pageCount"/>
                           </span>
                           页                  </div>
                    </td>                <td width="30%">&nbsp;
                         &nbsp;&nbsp;&nbsp;&nbsp;转到
                            <input id=pid size=4 name=pid>
                         页
                         <input onClick="javascript:gotoPage(pid.value,<%=infoPageCount%>)" type=button value=go name=Submit>
                    </td>
                  </tr>
                  </tbody>
                </table>
              </td>
            </tr>
            </tbody>
          </table>
          <script language="javascript">
            function gotoPage(n,m)//n 去的页, m总页数
            {
                if(IsInt(n))
                {
                    if(n==0)
                    {
                        alert("请输入自然数!");
                        return;
                    }
                                    if(n <= m)
                    {
                        window.location='./?classID=<%=tmpid%>&pgno='+pid.value+'&parentID=<%=request.getParameter("parentID") %>&order=<%=request.getParameter("order")%>&pageSize=<%=pagesize %>';
                    }
                    else
                    {
                        alert("输入的页数大于总页数!");
                    }
                }
                else
                {
                    alert("请输入自然数!");
                }
            }
          </script>
    用到了TAG,你就看看分页机制就可以了。