小弟是菜鸟,在调试一个jsp分页程序时出现这样一个错误,请各位大虾们帮忙解决一下,不胜感激!!>>>>>>>>>
type Exception report message 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 63 60: 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
我的程序的源代码是>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
<%@ 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> 

解决方案 »

  1.   

    看看rs1有没有值,试试不要用select * ,改为select 字段
      

  2.   

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

    改成
    while(n <(pageSize)&&rs1.next()) 

      

  3.   

    1,把type_scroll_sensitive改成type_scroll_insensitive,
    然后再按上一帖我说的改改试试。。
    2,哪本说里面抄来的代码吧 ??真实害人不浅啊 !!!
    建议去网上找个JSP+SERVLET+JAVABEAN的例子 。。
      

  4.   

    ^_^ 问题终于解决了 
      
    谢谢大家的帮助 特别感谢geovil和jason的帮助 改成这样就可以了 
     
    do {
    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>
        
      <% } while(n <(pageSize)&&rs1.next()) ;
      %>
      

  5.   

    输出少一条记录 
    检查一下这块的逻辑
    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);     下面的rs1 是查询出来的结果集你写的循环输出么问题
    应该是上面这块的吧
      

  6.   

    ....建议少考虑直接JSP分页,正如N层楼上所说使用JSP+Servlet+JavaBean比较好。也不要做这样的练习。JSP只用于显示数据。学习一下Servlet的处理方式,以及后期的框架,多用封装思想来解决这样的问题(如:封装一个分页类出来)