springboot druid 数据库批量更新错误 multi-statement not allow
Posted mangues
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了springboot druid 数据库批量更新错误 multi-statement not allow相关的知识,希望对你有一定的参考价值。
springboot druid 在写批量更新的时候出现错误
Caused by: java.sql.SQLException: sql injection violation, multi-statement not allow com.alibaba.druid.wall.WallFilter.check(WallFilter.java:714)
at com.alibaba.druid.wall.WallFilter.connection_prepareStatement(WallFilter.java:240)
at com.alibaba.druid.filter.FilterChainImpl.connection_prepareStatement(FilterChainImpl.java:448)
at com.alibaba.druid.filter.FilterAdapter.connection_prepareStatement(FilterAdapter.java:928)
at com.alibaba.druid.filter.FilterEventAdapter.connection_prepareStatement(FilterEventAdapter.java:122)
at com.alibaba.druid.filter.FilterChainImpl.connection_prepareStatement(FilterChainImpl.java:448)
at com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl.prepareStatement(ConnectionProxyImpl.java:342)
at com.alibaba.druid.pool.DruidPooledConnection.prepareStatement(DruidPooledConnection.java:318)
需要WallConfig设置multiStatementAllow=true
@Configuration
public class DruidDBConfig
private Logger logger = LoggerFactory.getLogger(DruidDBConfig.class);
@Bean //声明其为Bean实例
@Primary //在同样的DataSource中,首先使用被标注的DataSource
@ConfigurationProperties(prefix = "spring.datasource")
public DataSource dataSource()
DruidDataSource datasource = new DruidDataSource();
List<Filter> filters = new ArrayList<>();
filters.add(wallFilter);
datasource.setProxyFilters(filters);
return datasource;
@Autowired
WallFilter wallFilter;
@Bean(name = "wallConfig")
WallConfig wallFilterConfig()
WallConfig wc = new WallConfig ();
wc.setMultiStatementAllow(true);
return wc;
@Bean(name = "wallFilter")
@DependsOn("wallConfig")
WallFilter wallFilter(WallConfig wallConfig)
WallFilter wfilter = new WallFilter ();
wfilter.setConfig(wallConfig);
return wfilter;
以上是关于springboot druid 数据库批量更新错误 multi-statement not allow的主要内容,如果未能解决你的问题,请参考以下文章
SpringBoot+Mybatis+Druid批量更新 multi-statement not allow异常
SpringBoot MyBatis druid数据库连接池
Spring Boot 集成 Druid 批量插入数据和效率监控配置