📄 deletedb.java
字号:
package common;
import java.sql.*;
/**
* @author 隋玉杰 E-mail: suiyj1158@hotmail.com
* @version 创建时间:Nov 19, 2008 6:06:46 AM 类说明
*/
public class DeleteDb {
/**
* @author 隋玉杰 E-mail: suiyj1158@hotmail.com
* @version 创建时间:Nov 19, 2008 6:06:47 AM 循环找出要删除的子类
*/
public void delsontype(int c_id) {
Connection conn = DAO.getConnection();
Statement stmt = null;
ResultSet rs = null;
String tempfid = "";
try {
stmt = conn.createStatement();
// 删除要删除的父类
String sql = "update t_type set c_isdel=0 where c_id=" + c_id;
stmt.executeUpdate(sql);
// 删除这个父类下面的文件
sql = "update t_file set c_isdel=0 where c_typeid=" + c_id;
stmt.executeUpdate(sql);
// 查找要删除的第一级子类,存入字符串tempfid
sql = "select c_id from t_type where c_isdel=1 and c_fid =" + c_id;
rs = stmt.executeQuery(sql);
while (rs.next()) {
tempfid = tempfid + "," + rs.getInt(1);
}
if (tempfid.length() > 1) {
tempfid = tempfid.substring(1);
}
// 删除更低级的子类
while (tempfid.length() > 1) {
// 删除查到的子类
sql = "update t_type set c_isdel=0 where c_isdel=1 and c_id in ("
+ tempfid + ")";
stmt.executeUpdate(sql);
// 删除这些子类下面的文件
sql = "update t_file set c_isdel=0 where c_isdel=1 and c_typeid in ("
+ tempfid + ")";
stmt.executeUpdate(sql);
// 查找这些子类更低一级的子类
sql = "select c_id from t_type where c_isdel=1 and c_fid in ("
+ tempfid + ")";
tempfid = "";
rs = stmt.executeQuery(sql);
while (rs.next()) {
tempfid = tempfid + "," + rs.getInt(1);
}
if (tempfid.length() > 1) {
tempfid = tempfid.substring(1);
}
}
rs.close();
stmt.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
DeleteDb db = new DeleteDb();
int c_id = 1;
db.delsontype(c_id);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -