大家帮忙看看,其实程序简单,帮我看看,运行产生:ResutlSet is closed.请大家指教。万般感谢
//:pagescount.java
package fanye;import java.sql.*;public class pagescount {
  public static Connection getConnection() throws SQLException {
    try {
      Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    }
    catch (ClassNotFoundException e) {
      e.printStackTrace();
    }
    return DriverManager.getConnection("jdbc:odbc:bookDB", "sa", "sa");
  }
}
//:pages.jsp
<%@ page contentType="text/html; charset=GBK" %>
<%@ page import="java.sql.*"%>
<%@ page import="fanye.*"%>
<jsp:userBean id="userBean" scope="page" class="fanye.pagescount"/>
<%
Connection conn=null;
Statement stat=null;
ResultSet rs=null;
try{
conn=pagescount.getConnection();
stat=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
rs=stat.executeQuery("SELECT * FROM book");
}
finally{
if(conn!=null)
   conn.close();
}
while(rs.next()){
%>
<html>
<head>
<title>
pages
</title><font size=2>
<table width="600" border="1" align="center" cellpadding="1" cellspacing="1">
  <tr>
    <td>书籍编号</td>
    <td><%=rs.getString("BookDB")%></td>
    <td>出版日期</td>
    <td>&nbsp;</td>
    <td>总页数</td>
    <td>&nbsp;</td>
    <td>价格</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>书籍名称</td>
    <td colspan="5">&nbsp;</td>
    <td>作者</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>备注</td>
    <td colspan="7">&nbsp;</td>
  </tr>
</table>
</font>
</body>
</html>
<%}%>

解决方案 »

  1.   

    //:pages.jsp
    <%@ page contentType="text/html; charset=GBK" %>
    <%@ page import="java.sql.*"%>
    <%@ page import="fanye.*"%>
    <jsp:userBean id="userBean" scope="page" class="fanye.pagescount"/>
    <%
    Connection conn=null;
    Statement stat=null;
    ResultSet rs=null;
    try{
    conn=pagescount.getConnection();
    stat=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
    rs=stat.executeQuery("SELECT * FROM book");while(rs.next()){
    %>
    <html>
    <head>
    <title>
    pages
    </title><font size=2>
    <table width="600" border="1" align="center" cellpadding="1" cellspacing="1">
    <tr>
    <td>书籍编号</td>
    <td><%=rs.getString("BookDB")%></td>
    <td>出版日期</td>
    <td>&nbsp;</td>
    <td>总页数</td>
    <td>&nbsp;</td>
    <td>价格</td>
    <td>&nbsp;</td>
    </tr>
    <tr>
    <td>书籍名称</td>
    <td colspan="5">&nbsp;</td>
    <td>作者</td>
    <td>&nbsp;</td>
    </tr>
    <tr>
    <td>备注</td>
    <td colspan="7">&nbsp;</td>
    </tr>
    </table>
    </font>
    </body>
    </html>
    <%}
    finally{
    if(conn!=null)
    conn.close();
    }}%>
    close conn,会把rs也关闭,因此,对于你的代码,请先取完数据之后在关闭conn
      

  2.   

    把这段移到最后去
    if(conn!=null)
       conn.close();
    }这样:
    <%
    if(conn!=null)
       conn.close();
    }
    }%>
      

  3.   

    在JSP页面捕捉一下错误,加一个Catch语句再看看
      

  4.   

    <%
    Connection conn=null;
    Statement stat=null;
    ResultSet rs=null;
    try{
    conn=pagescount.getConnection();
    stat=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
    rs=stat.executeQuery("SELECT * FROM book");
    }
    finally{
    if(conn!=null)
       conn.close();//错误在这边
    }
    while(rs.next()){//conn都close掉了rs怎么不会close掉
    %>
    if(conn!=null)
       conn.close();
    }
    应该在执行完while(rs.next()){后执行
      

  5.   

    我晕啊,东西还没读出来你关闭conn干什么?