用weblogic資料庫連線池遞迴呼叫實現樹形目錄出錯

zyc21st發表於2004-04-19
public class menu_tree implements Serializable{

DBConn myDBConn = new DBConn();
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;

public ResultSet executeQuery(String sql){

try {
conn = myDBConn.getConnection();
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
rs = stmt.executeQuery(sql);
}
catch (SQLException e) {
System.err.println(e.toString());
}
return rs;
}


}
public void buildTree(javax.servlet.jsp.JspWriter out,int parentid,int level)
throws Exception{
menu_tree conn=new menu_tree();
level++;
ResultSet rs = conn.executeQuery(
"select * from MENU_TREE where PARENTID=" + parentid + "order by ID");
while (rs.next()) {
out.println("<div>");
for (int i = 0; i < level - 1; i++)
out.print("<img src=\"images/white.gif\"> ");
id1=rs.getInt("ID");
boolean resu=has_child(id1);
out.println(resu);
if (resu) {
out.print("<img alt=\"展開\" style=\"cursor:hand;\" onclick=\"myClick('"+rs.getInt("ID") + "');\" ID=\"img" + rs.getInt("ID") + "\" src=\"images/plus.gif\"> <img ID=\"im" + rs.getInt("ID")+"\" src=\"images/closedfold.gif\"> ");
out.print("<span onclick=\"myClick1('" + rs.getInt("id") +
"');\" style=\"cursor:default;\" ID=\"span" +
rs.getInt("ID") + "\">" + rs.getString("MENU") + "</span>");
out.println("<div style=\"display:none;\" ID=\"div" + rs.getInt("ID") +
"\">");
// out.println(rs.getInt("ID") ) ;
buildTree(out,id1,level); //遞迴呼叫
out.println("</div>");
}
else
out.print("<img src=\"images/minus.gif\"> <img src=\"images/openfold.gif\"> <span onclick=\"myClick1('" +
rs.getInt("id") +
"');\" style=\"cursor:default;\" ID=\"span" +
rs.getInt("ID") + "\">" + rs.getString("MENU") + "</span>");
out.println("</div>");
}
rs.close();
rs=null;



}

private boolean has_child(int parentid) throws Exception {

ResultSet rs=conn.executeQuery("select * from MENU_TREE where PARENTID="+parentid+"order by ID");


return rs.next();

}
其中DBConn是用weblogic資料庫連線池連線oracle資料庫,但是該段程式碼在遞迴呼叫處出錯,但是如果不用連線池,DBConn直接連線oracle資料庫,則沒有出錯,能正常顯示樹形目錄,是不是用連線池需要清理記憶體,該如何解決?

相關文章