67,518
社区成员
发帖
与我相关
我的任务
分享
public void deleteCourseInfo(String courseId) throws Exception {
Connection con = pStrategy.getDBConnection();
con.setAutoCommit(false);
try {
Statement stmt = con.createStatement();
Map tb = AllCourseInfoTable.getTable();
Iterator it = tb.entrySet().iterator();
while(it.hasNext()){
Map.Entry entry = (Map.Entry)it.next();
String tableName = (String)entry.getKey();
String propertyName = (String)entry.getValue();
String sql = "delete from " + tableName + " where " + propertyName + " = " + courseId;
con.prepareStatement(sql);
stmt.addBatch(sql);
}
stmt.executeBatch();
con.commit();
if (stmt != null) {
stmt.close();
stmt = null;
}
}catch(Exception e){
try {
con.rollback();
} catch (SQLException e1) {
throw new Exception();
}
throw new Exception();
}finally{
try {
con.close();
} catch (SQLException ex) {
throw new Exception();
}
}
}
public void deleteCourseInfo(String courseId) throws Exception {
Connection con = pStrategy.getDBConnection();
con.setAutoCommit(false);
try {
Statement stmt = con.createStatement();
Map tb = AllCourseInfoTable.getTable();
Iterator it = tb.entrySet().iterator();
while(it.hasNext()){
Map.Entry entry = (Map.Entry)it.next();
String tableName = (String)entry.getKey();
String propertyName = (String)entry.getValue();
String sql = "delete from " + tableName + " where " + propertyName + " = " + courseId;
//con.prepareStatement(sql);
stmt.addBatch(sql);
}
stmt.executeBatch();
con.commit();
if (stmt != null) {
stmt.close();
stmt = null;
}
}catch(Exception e){
try {
con.rollback();
} catch (SQLException e1) {
throw new Exception();
}
throw new Exception();
}finally{
try {
con.close();
} catch (SQLException ex) {
throw new Exception();
}
}
}