首页 > 其他 > 详细

反射实现增删改查(DAO层)——删除数据

时间:2018-05-19 23:16:35      阅读:394      评论:0      收藏:0      [点我收藏+]
先贴出代码,后续补充自己的思路、配置文件、使用方式:
/**
     * 
     *  删除数据
     */
    @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);
        }

    }

反射实现增删改查(DAO层)——删除数据

原文:https://www.cnblogs.com/caoleiCoding/p/9061931.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!