谁能帮我看看jsp页面为什么抛这个异常
这是一个实现BBS帖子展现的jsp页面 可是每次用浏览器打开时会抛出:java.sql.SQLException: Operation not allowed after ResultSet closedShowArticleTree.jsp:<%@ page language="java" contentType="text/html; charset=GBK"
pageEncoding="GBK"%>
<%@ page import="java.sql.*,com.libra.bbs.*,java.util.*"%>
<%
String admin = (String) session.getAttribute("admin");
if (admin != null && admin.equals("true")) {
blogin = true;
}
%>
<%!boolean blogin = false;
private void tree(List<Article> articles, Connection conn, int id, int grade) {
String sql = "select * from article where pid =" + id;
Statement stmt = DBase.createStmt(conn);
ResultSet rs = DBase.executeQuery(stmt, sql);
try {
while (rs.next()) {
Article ar = new Article();
ar.initFromRs(rs);
ar.setGrade(grade);
articles.add(ar);
if (!ar.isLeaf()) {
tree(articles, conn, ar.getId(), grade + 1);
}
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBase.close(rs);
DBase.close(stmt);
}
}%>
<%
List<Article> articles = new ArrayList<Article>();
Connection conn = DBase.getConn();
tree(articles, conn, 0, 0);
DBase.close(conn);
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title>Insert title here</title>
</head>
<body>
<h1>BBS帖子输出</h1>
<a href="Post.jsp">发表主题</a>
<table border="1">
<%
for (Iterator<Article> it = articles.iterator(); it.hasNext();) {
Article a = it.next();
String preStr = "";
for (int i = 0; i < a.getGrade(); i++) {
preStr += "----";
}
%>
<tr>
<td><%=a.getId()%></td>
<td><a href="ShowArticleDetail.jsp?id=<%=a.getId()%>"> <%=preStr + a.getTitle()%>
</a></td>
<%
if (blogin) {
%>
<td><a href="Delete.jsp?id=<%=a.getId()%>&pid=<%=a.getPid()%>">删除</a></td>
<%
}
%>
</tr>
<%
}
%>
</table>
</body>
</html>
用到的两个JavaBean类:
package com.libra.bbs;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;
public class Article {
private int id;
private int pid; //private Article parent
private int rootId;
private String title;
private String cont;
private Date pdate;
private boolean isLeaf;
private int grade;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getPid() {
return pid;
}
public void setPid(int pid) {
this.pid = pid;
}
public int getRootId() {
return rootId;
}
public void setRootId(int rootId) {
this.rootId = rootId;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getCont() {
return cont;
}
public void setCont(String cont) {
this.cont = cont;
}
public Date getPdate() {
return pdate;
}
public void setPdate(Date pdate) {
this.pdate = pdate;
}
public boolean isLeaf() {
return isLeaf;
}
public void setLeaf(boolean isLeaf) {
this.isLeaf = isLeaf;
}
public int getGrade() {
return grade;
}
public void setGrade(int grade) {
this.grade = grade;
}
public void initFromRs(ResultSet rs) {
try {
setId(rs.getInt("id"));
setPid(rs.getInt("pid"));
setRootId(rs.getInt("rootid"));
setTitle(rs.getString("title"));
setLeaf(rs.getInt("isleaf") == 0 ? true : false);
setPdate(rs.getTimestamp("pdate"));
setCont(rs.getString("cont"));
setGrade(0);
} catch (SQLException e) {
e.printStackTrace();
}
}
}
package com.libra.bbs;
import java.sql.*;
public class DBase {
public static Connection getConn(){
Connection conn = null;
try {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/bbs", "root" , "root");
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return conn ;
}
public static Statement createStmt(Connection conn){
Statement stmt = null ;
try{
stmt = conn.createStatement();
}catch(SQLException e){
e.printStackTrace();
}
return stmt ;
}
public static PreparedStatement createPstmt(Connection conn,String sql){
PreparedStatement pStmt = null ;
try{
pStmt = conn.prepareStatement(sql);
}catch(SQLException e){
e.printStackTrace();
}
return pStmt ;
}
public static int executeUpdate(Connection conn, String sql) {
int ret = 0;
Statement stmt = null;
try {
stmt = conn.createStatement();
ret = stmt.executeUpdate(sql);
} catch (SQLException e) {
e.printStackTrace();
} finally {
close(stmt);
}
return ret;
}
public static ResultSet executeQuery(Statement stmt,String sql){
ResultSet rs = null ;
try{
rs = stmt.executeQuery(sql);
}catch(SQLException e ){
e.printStackTrace();
}finally{
close(stmt);
}
return rs ;
}
public static void close(Connection conn){
if(conn!= null){
try{
conn.close();
}catch(SQLException e){
e.printStackTrace();
}
conn = null ;
}
}
public static void close(Statement stmt){
if(stmt!= null){
try{
stmt.close();
}catch(SQLException e){
e.printStackTrace();
}
stmt = null ;
}
}
public static void close(ResultSet rs){
if(rs!= null){
try{
rs.close();
}catch(SQLException e){
e.printStackTrace();
}
rs = null ;
}
}
}