下面的一个方法是删除一个目录树参数指定该目录的id及是否是叶子节点(0为叶子节点返回true)
具体实现是有递归先删除该节点的叶子节点,最后删除本身(执行的delete语句)。
我的问题是:删除叶子节点(子目录)并没有调用delete语句怎么就删除了呢??public static void categoryDelete(int id, boolean isLeaf) {
Connection conn = null ;
Statement stmt = null ;
ResultSet rs = null ;
String sql_child = "select * from category where pid = " + id;
conn = DB.getConn();
stmt = DB.getStmt(conn);
rs = DB.executeQuery(stmt, sql_child);
if(!isLeaf){
try {
while (rs.next()) {
categoryDelete(rs.getInt("id"), rs.getInt("leaf")==0);
}
} catch (SQLException e) {
e.printStackTrace();
}finally{
DB.closeRs(rs);
DB.closeStmt(stmt);
}
}
//删除该目录
String sql_self = "delete from category where id = "+ id ;
DB.executeUpdate(conn, sql_self);
}
具体实现是有递归先删除该节点的叶子节点,最后删除本身(执行的delete语句)。
我的问题是:删除叶子节点(子目录)并没有调用delete语句怎么就删除了呢??public static void categoryDelete(int id, boolean isLeaf) {
Connection conn = null ;
Statement stmt = null ;
ResultSet rs = null ;
String sql_child = "select * from category where pid = " + id;
conn = DB.getConn();
stmt = DB.getStmt(conn);
rs = DB.executeQuery(stmt, sql_child);
if(!isLeaf){
try {
while (rs.next()) {
categoryDelete(rs.getInt("id"), rs.getInt("leaf")==0);
}
} catch (SQLException e) {
e.printStackTrace();
}finally{
DB.closeRs(rs);
DB.closeStmt(stmt);
}
}
//删除该目录
String sql_self = "delete from category where id = "+ id ;
DB.executeUpdate(conn, sql_self);
}
String sql_self = "delete from category where id = "+ id ;
因为这里的ID是是递归传过来的ID 直接就删除了。
String sql_self = "delete from category where id = "+ id ;
明白了 结贴
主要是下面的
categoryDelete(rs.getInt("id"), rs.getInt("leaf")==0); 所以如果不是叶子节点id一直在变 最后还是调用delete语句了