sql injection violation, comment not allow, mybatis,mysql,诡异的错误. sql语句可以执行,但是用mybatis操作就报错.

//读取数据库配置
		loadPropertyFile("classes/config/mysql.properties");
		DruidPlugin dp = new DruidPlugin(getProperty("jdbcUrl"),getProperty("user"),getProperty("password"));

		//WallFilter wall = new WallFilter();
		//wall.setDbType(getProperty("dbType"));
		//dp.addFilter(wall);

最简单粗暴的方式就是将配置的wall去掉。 问题搞定!


spring: cloud: inetutils: # 默认网段 preferred-networks: 192.168.0 # 忽略指定正则匹配的网卡的配置,我这里配置了VM虚拟机和Docker的 ignored-interfaces: ['VMware.*','Hyper-V.*'] datasource: druid: stat-view-servlet: enabled: true loginUsername: admin loginPassword: zckj@11056 allow: web-stat-filter: enabled: true dynamic: primary: multi-gim init-all-enabled: false init-data-source: master,multi-gim,multi-gabst dynaDataSourceTarget: multi-gim druid: # 全局druid参数,绝大部分值和默认保持一致。(现已支持的参数如下,不清楚含义不要乱设置) # 连接池的配置信息 # 初始化大小,最小,最大 initial-size: 5 min-idle: 5 maxActive: 20 # 配置获取连接等待超时的时间 maxWait: 60000 # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 timeBetweenEvictionRunsMillis: 60000 # 配置一个连接在池中最小生存的时间,单位是毫秒 minEvictableIdleTimeMillis: 300000 # validationQuery: SELECT 1 testWhileIdle: true testOnBorrow: false testOnReturn: false # 打开PSCache,并且指定每个连接上PSCache的大小 poolPreparedStatements: true maxPoolPreparedStatementPerConnectionSize: 20 # 配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙 filters: stat,wall,slf4j # 通过connectProperties属性来打开mergeSql功能;慢SQL记录 connectionProperties: druid.stat.mergeSql\=true;druid.stat.slowSqlMillis\=5000 # 多数据源配置 datasource: master: url: jdbc:postgresql://192.168.0.137:15432/nacos # url: jdbc:postgresql://192.168.89.18:15432/nacos username: postgres password: zckj@110 driver-class-name: org.postgresql.Driver druid: validationQuery: SELECT 1 multi-gabst: url: jdbc:postgresql://192.168.0.137:15432/alarm # url: jdbc:postgresql://192.168.89.18:15432/alarm username: postgres password: zckj@110 driver-class-name: org.postgresql.Driver druid: wall: hint-allow: true validationQuery: SELECT 1 为什么报错2025-07-23 15:23:33.539 [main] ERROR org.springframework.boot.SpringApplication:837 - Application run failed java.lang.IllegalStateException: Failed to execute CommandLineRunner at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:798) at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:779) at org.springframework.boot.SpringApplication.run(SpringApplication.java:322) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) at org.jeecg.ServerJwqwCloudApplication.main(ServerJwqwCloudApplication.java:29) Caused by: org.springframework.jdbc.UncategorizedSQLException: ### Error querying database. Cause: java.sql.SQLException: sql injection violation, comment not allow :
07-24
报错 `java.sql.SQLException: sql injection violation, dbType mysql, druid-version 1.2.4, multi-statement not allow` 表明在使用 Druid 连接 MySQL 数据库时,由于安全策略限制,不允许执行多条 SQL 语句。以下是一些可能的解决方法: ### 调整 Druid 配置 在 Druid 的配置中,开启多语句执行的支持。以 Spring Boot 为例,可以在 `application.properties` 或 `application.yml` 中进行配置: **application.properties** ```properties spring.datasource.druid.filter.wall.config.multi-statement-allow=true ``` **application.yml** ```yaml spring: datasource: druid: filter: wall: config: multi-statement-allow: true ``` ### 拆分 SQL 语句 如果不希望开启多语句执行支持,可以将多条 SQL 语句拆分成单个语句分别执行。例如,在 Java 代码中使用 JDBC 时: ```java import java.sql.Connection; import java.sql.DriverManager; import java.sql.Statement; public class SplitSqlExample { public static void main(String[] args) { try (Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/yourdb", "username", "password"); Statement stmt = conn.createStatement()) { // 第一条 SQL 语句 String sql1 = "UPDATE your_table SET column1 = 'value1' WHERE id = 1"; stmt.executeUpdate(sql1); // 第二条 SQL 语句 String sql2 = "UPDATE your_table SET column2 = 'value2' WHERE id = 2"; stmt.executeUpdate(sql2); } catch (Exception e) { e.printStackTrace(); } } } ``` ### 检查代码逻辑 确保代码中没有不必要的多语句拼接,避免出现类似问题。 ### 升级 Druid 版本 有时,该问题可能是由于 Druid 版本的 bug 导致的。可以尝试升级到较新的稳定版本,查看问题是否解决。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值