【发布时间】:2018-01-30 20:34:47
【问题描述】:
我正在尝试从数据库中删除行作为批量更新操作。我已经编写了以下方法来完成任务,但是当我执行时,它不会从表中删除条目。所以表保持不变。 如果代码中有任何错误,请告诉我。
public void removeFromDb(String partnerId, List<String> packagedServiceIdList) throws CustomException {
Connection con = null;
PreparedStatement ps = null;
try {
con = getConnection();
ps = con.prepareStatement(REMOVE_DATA_MAP);
for(int i=0; i<packagedServiceIdList.size();i++) {
ps.setString(1, partnerId);
ps.setString(2, packagedServiceIdList.get(i));
ps.addBatch();
gLogger.debug("query is: "+ps.toString());
}
ps.executeUpdate();
} catch (SQLException sqle) {
gLogger.error("Exception while removing the record from table, SQLException:{}", sqle);
throw new CustomException(feErrorEnum.INTERNAL_EXCEPTION, sqle.getMessage());
} finally {
closeConnection(con, ps, null);
}
}
【问题讨论】: