private void delete(Connection conn, int id, boolean isLeaf) {
//delete all the children
//delete(conn, chids's id)

if(!isLeaf) { 
String sql = "select * from article where pid = " + id;
Statement stmt = DB.createStmt(conn);
ResultSet rs = DB.executeQuery(stmt, sql); 
try {
while(rs.next()) {
delete(conn, rs.getInt("id"), rs.getInt("isleaf") == 0);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
DB.close(rs);
DB.close(stmt);
}
}


//delete self
DB.executeUpdate(conn, "delete from article where id = " + id);


}这是一段JSP中的删除帖子程序, 应用是先删除主帖下的子贴,再删除主帖,请高手指教在删除子贴的那段程序里,并没有执行SQL语句 数据库是如何删除的,另如果程序运行到while(rs.next()) {
delete(conn, rs.getInt("id"), rs.getInt("isleaf") == 0);
}
这时候是继续往下运行还是回到private void delete(Connection conn, int id, boolean isLeaf){}运行

解决方案 »

  1.   

    回到private void delete(Connection conn, int id, boolean isLeaf){}运行
      

  2.   

    感觉你这程序没什么问题吧,递归遍历子节点,到叶子之后执行DB.executeUpdate删除,然后往上删除父节点
      

  3.   


    但是程序运行时 确实节点已被删除 纠结ING
      

  4.   


    DB.executeUpdate 也没有删除的SQL语句啊
      

  5.   


    DB.executeUpdate 删除的不是最根上的么 where id = id
      

  6.   

    递归的 
    最先删除的是子节点,再回来删除根上的while(rs.next()) {
    delete(conn, rs.getInt("id"), rs.getInt("isleaf") == 0);
    }
    这一段代码就是删除所有子节点,不知道你是否理解递归
      

  7.   

    1.DB.executeUpdate(conn, "delete from article where id = " + id);
    这个执行删除2.private void delete(Connection conn, int id, boolean isLeaf) ;
    当传进来的isLeaf为true的时候  就不执行下面的if(){...} 转而走1  
    当传进来的isLeaf为false的时候  执行2.  
    之后根据while(rs.next()) {
    delete(conn, rs.getInt("id"), rs.getInt("isleaf") == 0);
    } 来确递归传的isLeaf 值