• 解决springboot druid 数据库批量更新错误问题


    原文:https://www.2cto.com/kf/201712/706399.html

    springboot druid 数据库多SQL错误multi-statement not allow

    Caused by: java.sql.SQLException: sql injection violation, multi-statement not allowcom.alibaba.druid.wall.WallFilter.check(WallFilter.java:714) atcom.alibaba.druid.wall.WallFilter.connection_prepareStatement(WallFilter.java:240) atcom.alibaba.druid.filter.FilterChainImpl.connection_prepareStatement(FilterChainImpl.java:448) atcom.alibaba.druid.filter.FilterAdapter.connection_prepareStatement(FilterAdapter.java:928) atcom.alibaba.druid.filter.FilterEventAdapter.connection_prepareStatement(FilterEventAdapter.java:122) atcom.alibaba.druid.filter.FilterChainImpl.connection_prepareStatement(FilterChainImpl.java:448) atcom.alibaba.druid.proxy.jdbc.ConnectionProxyImpl.prepareStatement(ConnectionProxyImpl.java:342) atcom.alibaba.druid.pool.DruidPooledConnection.prepareStatement(DruidPooledConnection.java:318)

    解决方案:

    1、配置数据库连接,添加allowMultiQueries=true

    jdbc.url=jdbc:mysql://192.168.11.107:3306/alarm_db?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8

    2、如果需要开启wall监控,同时允许multiStatementAllow,就不要在application.yml中配置filter,自己定义

    //使用连接池dataSource

    @Bean

    @ConfigurationProperties(prefix = "spring.datasource")

    public DataSource dataSource() {

    DruidDataSource druidDataSource = new DruidDataSource();

    List filterList=new ArrayList<>();

    filterList.add(wallFilter());

    druidDataSource.setProxyFilters(filterList);

    return druidDataSource;

    }

    @Bean

    public WallFilter wallFilter(){

    WallFilter wallFilter=new WallFilter();

    wallFilter.setConfig(wallConfig());

    return wallFilter;

    }

    @Bean

    public WallConfig wallConfig(){

    WallConfig config =new WallConfig();

    config.setMultiStatementAllow(true);//允许一次执行多条语句

    config.setNoneBaseStatementAllow(true);//允许非基本语句的其他语句

    return config;

    }

  • 相关阅读:
    oracle存储过程+游标处理select数据
    C/C++中各种类型int、long、double、char表示范围(最大最小值)
    算法如功夫——C++ 用递归函数计算n的阶乘n!
    北邮iptv用WindowsMediaplayer打不开的解决的方法
    【hoj】2651 pie 二分查找
    抽象工厂模式
    Java NIO与IO的差别和比較
    spark未来的发展方向
    Android学习笔记(四十):Preference的使用
    android 原生应用、Web应用、混合应用优缺点分析
  • 原文地址:https://www.cnblogs.com/shihaiming/p/10344762.html
Copyright © 2020-2023  润新知