先贴出代码,后续补充自己的思路、配置文件、使用方式:
/**
*
* 删除数据
*/
@Override
public void deleteObject(List<Map<String, Object>> params, String tableName) {
StringBuilder sql = new StringBuilder(
"DELETE FROM order_info WHERE 1=1 ");
Connection connection = null;
PreparedStatement preparedStatement = null;
try {
connection = DBConnection.getConnection();
if (params != null && params.size() > 0) {
for (int i = 0; i < params.size(); i++) {
Map<String, Object> map = params.get(i);
sql.append(" AND " + map.get("name") + " "
+ map.get("rela") + " " + map.get("value") + " ");
}
}
connection = DBConnection.getConnection();
preparedStatement = connection.prepareStatement(sql.toString());
preparedStatement.executeLargeUpdate();
} catch (SQLException e) {
e.printStackTrace();
System.out.println("删除失败!");
} catch (IllegalArgumentException e) {
e.printStackTrace();
} finally {
DBConnection.close(connection, preparedStatement, null);
}
}
原文地址:https://www.cnblogs.com/caoleiCoding/p/9061931.html
时间: 2024-10-06 00:22:16