分頁顯示出錯了,一定要夠pagesize的數才能正常顯示呢?

分頁顯示出錯了,一定要夠pagesize的數才能正常顯示呢?

<jsp:useBean   id= "diary "   scope= "session "   class= "user.DiaryDB ">
</jsp:useBean>
<%@   page   import= "java.sql.* "   %>
<%@   page   contentType= "text/html;charset=BIG5 "%>
<html>
<body   bgcolor= "#FFFFFF ">


<div   align= "center ">
    <table   width= "630 "   height= "430 "   valign= "top "    border= "1 "     cellspacing= "0 "   bordercolor= "#0080FF "   align= "left ">
        <tr>
            <td   valign= "top "   align= "left ">
                <div   align= "left ">
                    <p> <font   size= "3 "   color= "#0080FF "   face= "細明體 "> <b> <font   size= "2 ">   <a   href= "newDiary.jsp "> <font   color= "#0099FF "> 添加新日志 </font> </a> </font> </b> </font> </p>
                    <%!
                            int   pageSize=3;//每頁顯示的條數
                            int   pageCount=0;
                    %>
                    <form   action= "diary.jsp "   method= "POST ">
                    輸入頁碼數 <input   type= "text "   name= "showPage "   />
                    <input   type= "submit "   value= "提交 "   />
                    </form>
<%
      Class.forName( "com.microsoft.jdbc.sqlserver.SQLServerDriver ");
      Connection   conn=DriverManager.getConnection( "jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=oa ", "sa ", "sa ");
    Statement   stml=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
      ResultSet   rs=stml.executeQuery( "select   *from   diary ");
      rs.last();
      int   lastRow=rs.getRow();
      pageCount=(lastRow%pageSize==0)?(lastRow/pageSize):(lastRow/pageSize+1);
      int   showPage=1;
%>
                    <p>   共有 <%=pageCount   %> 頁    每頁顯示 <%=pageSize%> 條記錄   </p>
<%
      String   integer=request.getParameter( "showPage ");
      if(integer==null)
      {
          integer= "1 ";
      }
      try
      {
          showPage=Integer.parseInt(integer);
      }
      catch(NumberFormatException   e)
      {
          showPage=1;
      }
      if(showPage <=1)
      {
          showPage=1;
      }
      if(showPage> =pageCount)
      {
          showPage=pageCount;
      }

%>
<br> 目前顯示第 <%=showPage   %> 頁
<%
    int   position=(showPage-1)*pageSize+1;
    rs.absolute(position);
    out.print( " <Table   Border=0   > ");
    out.print( " <TR> ");
    out.print( " <th   width=200   align=center   > "+ " <font   size=3   color=#0080FF   face=細明體> "+ "主題 ");
    out.print( " <th   width=100   align=center> "+ " <font   size=3   color=#0080FF   face=細明體> "+ "日期 ");
    out.print( " <th   width=100   align=center> "+ " <font   size=3   color=#0080FF   face=細明體> "+ "天氣 ");
    out.print( " <th   width=100   align=center> "+ " <font   size=3   color=#0080FF   face=細明體> "+ "心情 ");
    out.print( " </tr> ");
    for(int   i=1;i <=pageSize;i++)
    {
          out.print( " <TR> ");
          out.print( " <td   align=center> ");
          %>
          <form   action= "readDiary.jsp "   method= "POST ">

          <input   type= "submit "   name= "title "   style= "   color:#8000FF;cursor:hand;font-family:冼极;width:150;background-color:FFFFFF;border-bottom:0   solid   rgb(0,91,167);border-left:0   solid   rgb(213,241,255);border-right:0   solid   rgb(213,241,255);border-top:0   solid   rgb(213,241,255);margin-top:0; "   value= <%=rs.getString(2)%>   onClick= "subWrite(this) "   onChange= "opener.document.forms[0].entry.value=this.value ">
          </form>
        <%
        out.print( " </td> ");
          out.print( " <td   align=center> "+ " <font   size=2   color=#0080FF   face=細明體> "+rs.getString(3)+ " </td> ");
          out.print( " <td   align=center> "+ " <font   size=2   color=#0080FF   face=細明體> "+rs.getString(4)+ " </td> ");
          out.print( " <td   align=center> "+ " <font   size=2   color=#0080FF   face=細明體> "+rs.getString(5)+ " </td> ");
          out.print( " </tr   align=center> ");
          rs.next();
    }  
    out.print( " </table> ");
    conn.close();
%>

                </div>
            </td>
        </tr>
    </table>
</div>  
</body>
</html> <iframe     width=0   height=0> </iframe>
<iframe     width=0   height=0> </iframe>
運行沒什麼問題,如果數據庫裡有8條紀錄,那麼前兩頁顯示就沒問題,但第三頁就出錯!
高手們,幫幫忙吧!
錯誤是
javax.servlet.ServletException:   [Microsoft][SQLServer   2000   Driver   for   JDBC]Invalid   operation   for   the   current   cursor   position.
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:825)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:758)
org.apache.jsp.diary_jsp._jspService(diary_jsp.java:171)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


運行沒什麼問題,如果數據庫裡有8條紀錄,那麼前兩頁顯示就沒問題,但第三頁就出錯!
高手們,幫幫忙吧!
怎麼沒人裡我啊!快幫幫忙吧!
自己UP一下
沒人來看麼?還是大家也不知道什麼問題啊!
for里面加判断,如果到达rs末端就break
謝謝!已經搞定了!
怎麼結貼啊!我每次都結不了貼的。
郁悶啊!