<%!CachedRowSetImpl rowSet;%>
<%
rowSet = (CachedRowSetImpl) session.getAttribute("rowSet");
int number = Integer.parseInt(request.getParameter("number"));
//rowSet.absolute(0);
rowSet.absolute(number);//将游标移动到Number行,如何将rowSet移动到第零行????
for (int i = 1; i <= 6; i++) {
out.print(rowSet.getString(i) + "  ");
                                     //读取第number行的第i列的数据并将其输出
}
%><br />我想得到rowSet行集中第一条的内容,rowSet.absolute(1)得到的是第二条的内容!
把光标移动到第0行,但是移动到第0行报出光标位置异常,那位大侠发发慈悲给解决一下,小弟在这里感激不尽!
即rowSet.absolute(0);报错
org.apache.jasper.JasperException: An exception occurred processing JSP page /poetry.jsp at line 3128: 
29:  <body bgcolor="ghostwhite">
30:  <%!CachedRowSetImpl rowSet;%>
31:  <%
32:  rowSet = (CachedRowSetImpl) session.getAttribute("rowSet");
33:  int number = Integer.parseInt(request.getParameter("number"));
34:  //rowSet.absolute(0);
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:524)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:417)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
root cause javax.servlet.ServletException: java.sql.SQLException: absolute: 光标位置无效
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:850)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:779)
org.apache.jsp.poetry_jsp._jspService(poetry_jsp.java:111)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)

解决方案 »

  1.   

    为啥不是第一行,而是第0行?
    你说的“我想得到rowSet行集中第一条的内容,rowSet.absolute(1)得到的是第二条的内容!”应该是其他问题导致的,根据Java API说明:absoluteboolean absolute(int row)
                     throws SQLException
    Moves the cursor to the given row number in this ResultSet object.
    If the row number is positive, the cursor moves to the given row number with respect to the beginning of the result set. The first row is row 1, the second is row 2, and so on.If the given row number is negative, the cursor moves to an absolute row position with respect to the end of the result set. For example, calling the method absolute(-1) positions the cursor on the last row; calling the method absolute(-2) moves the cursor to the next-to-last row, and so on.An attempt to position the cursor beyond the first/last row in the result set leaves the cursor before the first row or after the last row.Note: Calling absolute(1) is the same as calling first(). Calling absolute(-1) is the same as calling last().
      

  2.   

    如果你非常不相信absolute,那么可以换个函数验证下:
    boolean first()
                  throws SQLException
    Moves the cursor to the first row in this ResultSet object.
    Returns:
    true if the cursor is on a valid row; false if there are no rows in the result set
    Throws:
    SQLException - if a database access error occurs; this method is called on a closed result set or the result set type is TYPE_FORWARD_ONLY
    SQLFeatureNotSupportedException - if the JDBC driver does not support this method
    Since:
    1.2