<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>浏览试卷</title>
</head><body>
<jsp:useBean id="connect" class="mybean.Connect" scope="page">
</jsp:useBean>
<div align="left">以下是本门课程的所有单项选择题,请添加组成试卷:
<a href="llsj.jsp">返回</a></div>
<hr align="left" />
<div align="left">
  <%
String coursename=(String)session.getAttribute("coursename");
if(coursename==null)
response.sendRedirect("../../index.jsp");
String name=(String)session.getAttribute("name");
%>
<%
String sql1="select * from qmxzt where name='"+coursename+"'and type='选择题'";
Statement stmt1=connect.conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
Statement stmtcount=connect.conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);    
ResultSet rs1=null;
String timu=null;
rs1=stmt1.executeQuery(sql1);
String   sqlcount="select   count(*)   from  qmxzt where name='"+coursename+"'and type='选择题'";       
ResultSet   rscount=stmtcount.executeQuery(sqlcount);    
int   pageSize=5;   
int   rowCount=0;   //总的记录数       
  while   (rscount.next()){      
  rowCount=rscount.getInt(1);       
  }      
  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=0;      
  rs1.absolute(thepage+1);       
int i=0;
int id=0;
%>
 <strong>(一)单项选择题:</strong>
<table width="636" height="62" border="1" align="left" cellspacing="3">
  <%
while(n<(pageSize)&&!rs1.isAfterLast())
{
rs1.next();
n++;       
i++;
id=rs1.getInt("ID");
timu=rs1.getString("question");%>
  <tr><td width="533" height="28"><%=i%>&nbsp;<%=timu%>&nbsp;&nbsp;</td>
    <td width="87"><a href="zj.jsp?id=<%=id%>">选择为试题</a></td>
  </tr>
    
  <% } 
  %>
  <tr>
    <td height="23" colspan="2"><form   name="sinfo"   method="post"   action="xzt.jsp?type='选择题'"   onSubmit="return testform(this)">
      <p>第<%=currPage%>页   共<%=pageCount%>页   共<%=rowCount%>条     
    
    <%if(currPage>1){%>
    <a   href="xzt.jsp?xzt.jsp?type='选择题'">首页</a>
    <%}%>     
    
    <%if(currPage>1){%>
    <a   href="xzt.jsp?page=<%=currPage-1%>&type='选择题'">上一页</a>
    <%}%>     
    
    <%if(currPage<pageCount){%>
    <a   href="xzt.jsp?page=<%=currPage+1%>&type='选择题'">下一页</a>
    <%}%>     
    
    <%if(pageCount>1){%>
    <a   href="xzt.jsp?page=<%=pageCount%>&type='选择题'">尾页</a>
    <%}%>     
    
  跳到
  <input   type="text"   name="page"   size="4"   style="font-size:9px">
  页     
    
  <input   type="submit"   name="submit"   size="4"   value="GO"   style="font-size:9px">     
  </p>
</form>  </td>
</tr>
</table> 
<p>&nbsp;</p><p>&nbsp;</p>
<p>  </p>
<p>&nbsp;</p>
</body>
<%
rs1.close();
rs1=null;
stmt1.close();
stmt1=null;
rscount.close();
rscount=null;
stmtcount.close();
stmtcount=null;
connect.closed();
  
%>
</html>
前几页能正常显示 一跳到最后一页就出现错误
错误提示----------------------------------------------------------------
type Exception reportmessage description The server encountered an internal error () that prevented it from fulfilling this request.exception org.apache.jasper.JasperException: An exception occurred processing JSP page /teacher/kaoshi/xzt.jsp at line 6360: rs1.next();
61: n++;       
62: i++;
63: id=rs1.getInt("ID");
64: timu=rs1.getString("question");
65: 
66: %>
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:515)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:408)
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: [Microsoft][ODBC 驱动程序管理器] 无效的游标状态
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:855)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:784)
org.apache.jsp.teacher.kaoshi.xzt_jsp._jspService(xzt_jsp.java:231)
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:384)
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 java.sql.SQLException: [Microsoft][ODBC 驱动程序管理器] 无效的游标状态
sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)
sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
sun.jdbc.odbc.JdbcOdbc.SQLGetDataInteger(Unknown Source)
sun.jdbc.odbc.JdbcOdbcResultSet.getDataInteger(Unknown Source)
sun.jdbc.odbc.JdbcOdbcResultSet.getInt(Unknown Source)
sun.jdbc.odbc.JdbcOdbcResultSet.getInt(Unknown Source)
org.apache.jsp.teacher.kaoshi.xzt_jsp._jspService(xzt_jsp.java:130)
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:384)
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)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.10 logs.
--------------------------------------------------------------------------------Apache Tomcat/6.0.10

解决方案 »

  1.   

    估计就是你的rs1.next()为空了,
    rs.next()最好都用if或while给括起来,有可能为空,然后关闭的时候也要先判断记录集和stmt是否为空再关闭。
      

  2.   


    while(n <(pageSize)&&!rs1.isAfterLast()) 

    rs1.next(){ 
    n++;      
    i++; 
    id=rs1.getInt("ID"); 
    timu=rs1.getString("question"); 
    %> 
      <tr> <td width="533" height="28"> <%=i%>&nbsp; <%=timu%>&nbsp;&nbsp; </td> 
        <td width="87"> <a href="zj.jsp?id= <%=id%>">选择为试题 </a> </td> 
      </tr> 
        
      <% } }
      %> 正确应该没问题..但我得告诉你..代码很乱..
      

  3.   


    while(n <(pageSize)&&!rs1.isAfterLast()) 

    while(rs1.next()){ 
    n++;      
    i++; 
    id=rs1.getInt("ID"); 
    timu=rs1.getString("question"); 
    %> 
      <tr> <td width="533" height="28"> <%=i%>&nbsp; <%=timu%>&nbsp;&nbsp; </td> 
        <td width="87"> <a href="zj.jsp?id= <%=id%>">选择为试题 </a> </td> 
      </tr> 
        
      <% } }
      %> 这样..
      

  4.   

    if (!rs1.next()){....}else{//error handle}
      

  5.   

    呵呵,也许没有结果集,如前面几个人所说
    java.sql.SQLException: [Microsoft][ODBC 驱动程序管理器] 无效的游标状态 你应该判断if(rs.next){
     . . 然后在里面做你的工作
      

  6.   

    等待解决中>>>  谢谢前面几位了 可是问题还是没有解决 >>>>
    希望继续知道>>>>>