关于级连删除的问题

03-04-28 月风

比如我有几层,比如中国新闻下面有很多地方新闻,每个地方新闻下面又有各个地方的行业新闻,等新闻,我现在需要做的是删除中国新闻,那么中国新闻下面的所有属于中国新闻的新闻全部删除。。请问如何做?我这里写了个程序,但是始终要出问题,请指正:

我思路是先删除最下层的内容,不管是否删除,再删除中间那层的内容,最后删除最上层的

public int delProductBigClass(String id) throws Exception

{

Mysql mysql = null;

String sql2 = "delete from product where Big=?";

String sql = "delete from productclass where Parent=?";

int ret = 0;

int ret1 = 0;

int ret2 = 0;

int ok = 0;

try

{

mysql = new Mysql(sql2);

mysql.setString(1,id);

ret2 = mysql.executeUpdate();

if(ret2==1 || ret2==0)

{

mysql.prepareStatement(sql);

mysql.setString(1,id);

ret = mysql.executeUpdate();

if(ret==1 || ret==0 || ret!=-1)

{

String sql1 = "delete from productclass where Id=?";

mysql.prepareStatement(sql1);

mysql.setString(1,id);

ret1 = mysql.executeUpdate();

if(ret1==1)

{

ok = 1;

}

}

}

}

catch(Exception e)

{

System.out.print(e);

}

finally

{

mysql.close();

}

return ok;

}