java mysql druid mybatis-plus里使用多表删除出错的一种处理方式

本文涉及的产品
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
RDS MySQL Serverless 高可用系列,价值2615元额度,1个月
简介: java mysql druid mybatis-plus里使用多表删除出错的一种处理方式

今天在出来多表删除的时候在mapper.xml用了下面的多个delete语句

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.nbcio.modules.flowable.mapper.FlowTaskMapper">
  <select id="queryActivityInstance" resultType="org.flowable.engine.impl.persistence.entity.ActivityInstanceEntityImpl">
        select t.* from
        act_ru_actinst t
       <where>
           <if test="processInstanceId !=null and processInstanceId != ''" >
              t.PROC_INST_ID_=#{processInstanceId} and ACT_TYPE_ = 'userTask' and  END_TIME_ is not null 
           </if>
           
       </where>
         order by t.END_TIME_ ASC
    </select>
    
    <delete id="deleteRunActinstsByIds" parameterType="java.util.List">
        delete from act_ru_actinst where ID_ in
        <foreach item="item" index="index" collection="list" open="(" separator="," close=")">
            #{item}
        </foreach>
    </delete>
    <delete id="deleteHisActinstsByIds" parameterType="java.util.List">
        delete from act_hi_actinst where ID_ in
        <foreach item="item" index="index" collection="list" open="(" separator="," close=")">
            #{item}
        </foreach>
    </delete>
    
    <delete id="deleteAllHisAndRun" parameterType="String">
      delete  from  act_ru_actinst  where proc_inst_id_ = #{processInstanceId}; 
      delete  from  act_ru_identitylink  where proc_inst_id_ = #{processInstanceId};
      delete  from  act_ru_task  where proc_inst_id_ = #{processInstanceId};
      delete  from  act_ru_variable  where proc_inst_id_ = #{processInstanceId};
      delete  from  act_ru_execution  where proc_inst_id_ = #{processInstanceId};
      delete  from  act_hi_actinst where proc_inst_id_ = #{processInstanceId};
      delete  from  act_hi_comment where proc_inst_id_ = #{processInstanceId};
      delete  from  act_hi_identitylink  where proc_inst_id_ = #{processInstanceId};
      delete  from  act_hi_procinst where proc_inst_id_ = #{processInstanceId};
      delete  from  act_hi_taskinst where proc_inst_id_ = #{processInstanceId};
      delete  from  act_hi_varinst  where proc_inst_id_ = #{processInstanceId};
    </delete>
</mapper>

   结果执行的时候出现下面错误

2023-08-19 10:32:22.408 [http-nio-8080-exec-6] [34mINFO [0;39m [36mo.j.c.util.security.AbstractQueryBlackListHandler:56[0;39m - 
--获取sql信息--
2023-08-19 10:32:32.175 [http-nio-8080-exec-4] [1;31mERROR[0;39m [36mo.jeecg.common.exception.JeecgBootExceptionHandler:69[0;39m - 
### Error updating database.  Cause: java.sql.SQLException: sql injection violation, dbType mysql, druid-version 1.2.15, multi-statement not allow : 
DELETE FROM act_ru_actinst WHERE proc_inst_id_ = ?;DELETE FROM act_ru_identitylink WHERE proc_inst_id_ = ?;DELETE FROM act_ru_task WHERE proc_inst_id_ = ?;DELETE FROM act_ru_variable WHERE proc_inst_id_ = ?;DELETE FROM act_ru_execution WHERE proc_inst_id_ = ?;DELETE FROM act_hi_actinst WHERE proc_inst_id_ = ?;DELETE FROM act_hi_comment WHERE proc_inst_id_ = ?;DELETE FROM act_hi_identitylink WHERE proc_inst_id_ = ?;DELETE FROM act_hi_procinst WHERE proc_inst_id_ = ?;DELETE FROM act_hi_taskinst WHERE proc_inst_id_ = ?;DELETE FROM act_hi_varinst WHERE proc_inst_id_ = ?
### The error may exist in file [F:\codestudy\nbcio-oa\develop\nbcio-boot\nbcio-boot-module-flowable\target\classes\com\nbcio\modules\flowable\mapper\xml\FlowTaskMapper.xml]
### The error may involve com.nbcio.modules.flowable.mapper.FlowTaskMapper.deleteAllHisAndRun
### The error occurred while executing an update
### SQL: DELETE FROM act_ru_actinst WHERE proc_inst_id_ = ?;DELETE FROM act_ru_identitylink WHERE proc_inst_id_ = ?;DELETE FROM act_ru_task WHERE proc_inst_id_ = ?;DELETE FROM act_ru_variable WHERE proc_inst_id_ = ?;DELETE FROM act_ru_execution WHERE proc_inst_id_ = ?;DELETE FROM act_hi_actinst WHERE proc_inst_id_ = ?;DELETE FROM act_hi_comment WHERE proc_inst_id_ = ?;DELETE FROM act_hi_identitylink WHERE proc_inst_id_ = ?;DELETE FROM act_hi_procinst WHERE proc_inst_id_ = ?;DELETE FROM act_hi_taskinst WHERE proc_inst_id_ = ?;DELETE FROM act_hi_varinst WHERE proc_inst_id_ = ?
### Cause: java.sql.SQLException: sql injection violation, dbType mysql, druid-version 1.2.15, multi-statement not allow : DELETE FROM act_ru_actinst WHERE proc_inst_id_ = ?;DELETE FROM act_ru_identitylink WHERE proc_inst_id_ = ?;DELETE FROM act_ru_task WHERE proc_inst_id_ = ?;DELETE FROM act_ru_variable WHERE proc_inst_id_ = ?;DELETE FROM act_ru_execution WHERE proc_inst_id_ = ?;DELETE FROM act_hi_actinst WHERE proc_inst_id_ = ?;DELETE FROM act_hi_comment WHERE proc_inst_id_ = ?;DELETE FROM act_hi_identitylink WHERE proc_inst_id_ = ?;DELETE FROM act_hi_procinst WHERE proc_inst_id_ = ?;DELETE FROM act_hi_taskinst WHERE proc_inst_id_ = ?;DELETE FROM act_hi_varinst WHERE proc_inst_id_ = ?
; uncategorized SQLException; SQL state [null]; error code [0]; sql injection violation, dbType mysql, druid-version 1.2.15, multi-statement not allow : DELETE FROM act_ru_actinst WHERE proc_inst_id_ = ?;DELETE FROM act_ru_identitylink WHERE proc_inst_id_ = ?;DELETE FROM act_ru_task WHERE proc_inst_id_ = ?;DELETE FROM act_ru_variable WHERE proc_inst_id_ = ?;DELETE FROM act_ru_execution WHERE proc_inst_id_ = ?;DELETE FROM act_hi_actinst WHERE proc_inst_id_ = ?;DELETE FROM act_hi_comment WHERE proc_inst_id_ = ?;DELETE FROM act_hi_identitylink WHERE proc_inst_id_ = ?;DELETE FROM act_hi_procinst WHERE proc_inst_id_ = ?;DELETE FROM act_hi_taskinst WHERE proc_inst_id_ = ?;DELETE FROM act_hi_varinst WHERE proc_inst_id_ = ?; nested exception is java.sql.SQLException: sql injection violation, dbType mysql, druid-version 1.2.15, multi-statement not allow : DELETE FROM act_ru_actinst WHERE proc_inst_id_ = ?;DELETE FROM act_ru_identitylink WHERE proc_inst_id_ = ?;DELETE FROM act_ru_task WHERE proc_inst_id_ = ?;DELETE FROM act_ru_variable WHERE proc_inst_id_ = ?;DELETE FROM act_ru_execution WHERE proc_inst_id_ = ?;DELETE FROM act_hi_actinst WHERE proc_inst_id_ = ?;DELETE FROM act_hi_comment WHERE proc_inst_id_ = ?;DELETE FROM act_hi_identitylink WHERE proc_inst_id_ = ?;DELETE FROM act_hi_procinst WHERE proc_inst_id_ = ?;DELETE FROM act_hi_taskinst WHERE proc_inst_id_ = ?;DELETE FROM act_hi_varinst WHERE proc_inst_id_ = ?
org.springframework.jdbc.UncategorizedSQLException: 
### Error updating database.  Cause: java.sql.SQLException: sql injection violation, dbType mysql, druid-version 1.2.15, multi-statement not allow : DELETE FROM act_ru_actinst WHERE proc_inst_id_ = ?;DELETE FROM act_ru_identitylink WHERE proc_inst_id_ = ?;DELETE FROM act_ru_task WHERE proc_inst_id_ = ?;DELETE FROM act_ru_variable WHERE proc_inst_id_ = ?;DELETE FROM act_ru_execution WHERE proc_inst_id_ = ?;DELETE FROM act_hi_actinst WHERE proc_inst_id_ = ?;DELETE FROM act_hi_comment WHERE proc_inst_id_ = ?;DELETE FROM act_hi_identitylink WHERE proc_inst_id_ = ?;DELETE FROM act_hi_procinst WHERE proc_inst_id_ = ?;DELETE FROM act_hi_taskinst WHERE proc_inst_id_ = ?;DELETE FROM act_hi_varinst WHERE proc_inst_id_ = ?
### The error may exist in file [F:\codestudy\nbcio-oa\develop\nbcio-boot\nbcio-boot-module-flowable\target\classes\com\nbcio\modules\flowable\mapper\xml\FlowTaskMapper.xml]
### The error may involve com.nbcio.modules.flowable.mapper.FlowTaskMapper.deleteAllHisAndRun
### The error occurred while executing an update
### SQL: DELETE FROM act_ru_actinst WHERE proc_inst_id_ = ?;DELETE FROM act_ru_identitylink WHERE proc_inst_id_ = ?;DELETE FROM act_ru_task WHERE proc_inst_id_ = ?;DELETE FROM act_ru_variable WHERE proc_inst_id_ = ?;DELETE FROM act_ru_execution WHERE proc_inst_id_ = ?;DELETE FROM act_hi_actinst WHERE proc_inst_id_ = ?;DELETE FROM act_hi_comment WHERE proc_inst_id_ = ?;DELETE FROM act_hi_identitylink WHERE proc_inst_id_ = ?;DELETE FROM act_hi_procinst WHERE proc_inst_id_ = ?;DELETE FROM act_hi_taskinst WHERE proc_inst_id_ = ?;DELETE FROM act_hi_varinst WHERE proc_inst_id_ = ?
### Cause: java.sql.SQLException: sql injection violation, dbType mysql, druid-version 1.2.15, multi-statement not allow : DELETE FROM act_ru_actinst WHERE proc_inst_id_ = ?;DELETE FROM act_ru_identitylink WHERE proc_inst_id_ = ?;DELETE FROM act_ru_task WHERE proc_inst_id_ = ?;DELETE FROM act_ru_variable WHERE proc_inst_id_ = ?;DELETE FROM act_ru_execution WHERE proc_inst_id_ = ?;DELETE FROM act_hi_actinst WHERE proc_inst_id_ = ?;DELETE FROM act_hi_comment WHERE proc_inst_id_ = ?;DELETE FROM act_hi_identitylink WHERE proc_inst_id_ = ?;DELETE FROM act_hi_procinst WHERE proc_inst_id_ = ?;DELETE FROM act_hi_taskinst WHERE proc_inst_id_ = ?;DELETE FROM act_hi_varinst WHERE proc_inst_id_ = ?
; uncategorized SQLException; SQL state [null]; error code [0]; sql injection violation, dbType mysql, druid-version 1.2.15, multi-statement not allow : DELETE FROM act_ru_actinst WHERE proc_inst_id_ = ?;DELETE FROM act_ru_identitylink WHERE proc_inst_id_ = ?;DELETE FROM act_ru_task WHERE proc_inst_id_ = ?;DELETE FROM act_ru_variable WHERE proc_inst_id_ = ?;DELETE FROM act_ru_execution WHERE proc_inst_id_ = ?;DELETE FROM act_hi_actinst WHERE proc_inst_id_ = ?;DELETE FROM act_hi_comment WHERE proc_inst_id_ = ?;DELETE FROM act_hi_identitylink WHERE proc_inst_id_ = ?;DELETE FROM act_hi_procinst WHERE proc_inst_id_ = ?;DELETE FROM act_hi_taskinst WHERE proc_inst_id_ = ?;DELETE FROM act_hi_varinst WHERE proc_inst_id_ = ?; nested exception is java.sql.SQLException: sql injection violation, dbType mysql, druid-version 1.2.15, multi-statement not allow : DELETE FROM act_ru_actinst WHERE proc_inst_id_ = ?;DELETE FROM act_ru_identitylink WHERE proc_inst_id_ = ?;DELETE FROM act_ru_task WHERE proc_inst_id_ = ?;DELETE FROM act_ru_variable WHERE proc_inst_id_ = ?;DELETE FROM act_ru_execution WHERE proc_inst_id_ = ?;DELETE FROM act_hi_actinst WHERE proc_inst_id_ = ?;DELETE FROM act_hi_comment WHERE proc_inst_id_ = ?;DELETE FROM act_hi_identitylink WHERE proc_inst_id_ = ?;DELETE FROM act_hi_procinst WHERE proc_inst_id_ = ?;DELETE FROM act_hi_taskinst WHERE proc_inst_id_ = ?;DELETE FROM act_hi_varinst WHERE proc_inst_id_ = ?
    at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:92)

主要是说druid不支持多表删除的操作,先相关资料实际上是可以配置druid进行多表操作

配置如下,sql连接增加&allowMultiQueries=true

url: jdbc:mysql://192.168.199.151:3306/nbcio-boot?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai&allowMultiQueries=true

同时druid里filters: stat,slf4j  这里去掉防火墙wall

     但这里也会引起一次多表操作的风险,不安全的时候风险也比较大,所以还是想办法考虑其它方式来处理为好。


相关实践学习
如何在云端创建MySQL数据库
开始实验后,系统会自动创建一台自建MySQL的 源数据库 ECS 实例和一台 目标数据库 RDS。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
1月前
|
关系型数据库 MySQL Java
【MySQL+java+jpa】MySQL数据返回项目的感悟
【MySQL+java+jpa】MySQL数据返回项目的感悟
43 1
|
1月前
|
关系型数据库 MySQL Java
【IDEA】java后台操作mysql数据库驱动常见错误解决方案
【IDEA】java后台操作mysql数据库驱动常见错误解决方案
61 0
|
1月前
|
Java 数据库连接 Maven
mybatis使用一:springboot整合mybatis、mybatis generator,使用逆向工程生成java代码。
这篇文章介绍了如何在Spring Boot项目中整合MyBatis和MyBatis Generator,使用逆向工程来自动生成Java代码,包括实体类、Mapper文件和Example文件,以提高开发效率。
105 2
mybatis使用一:springboot整合mybatis、mybatis generator,使用逆向工程生成java代码。
|
22天前
|
SQL Java 关系型数据库
java连接mysql查询数据(基础版,无框架)
【10月更文挑战第12天】该示例展示了如何使用Java通过JDBC连接MySQL数据库并查询数据。首先在项目中引入`mysql-connector-java`依赖,然后通过`JdbcUtil`类中的`main`方法实现数据库连接、执行SQL查询及结果处理,最后关闭相关资源。
|
1月前
|
关系型数据库 MySQL Java
java协程操作mysql数据库
本文介绍了如何在Java项目中使用虚拟线程和协程操作MySQL数据库,并通过代码示例展示了如何利用CompletableFuture实现非阻塞数据库连接和操作。
26 2
java协程操作mysql数据库
|
1月前
|
Java 关系型数据库 MySQL
springboot学习五:springboot整合Mybatis 连接 mysql数据库
这篇文章是关于如何使用Spring Boot整合MyBatis来连接MySQL数据库,并进行基本的增删改查操作的教程。
66 0
springboot学习五:springboot整合Mybatis 连接 mysql数据库
|
9天前
|
SQL 关系型数据库 MySQL
go语言数据库中mysql驱动安装
【11月更文挑战第2天】
23 4
|
7天前
|
SQL 关系型数据库 MySQL
12 PHP配置数据库MySQL
路老师分享了PHP操作MySQL数据库的方法,包括安装并连接MySQL服务器、选择数据库、执行SQL语句(如插入、更新、删除和查询),以及将结果集返回到数组。通过具体示例代码,详细介绍了每一步的操作流程,帮助读者快速入门PHP与MySQL的交互。
20 1
|
1月前
|
存储 关系型数据库 MySQL
Mysql(4)—数据库索引
数据库索引是用于提高数据检索效率的数据结构,类似于书籍中的索引。它允许用户快速找到数据,而无需扫描整个表。MySQL中的索引可以显著提升查询速度,使数据库操作更加高效。索引的发展经历了从无索引、简单索引到B-树、哈希索引、位图索引、全文索引等多个阶段。
61 3
Mysql(4)—数据库索引
|
16天前
|
监控 关系型数据库 MySQL
数据库优化:MySQL索引策略与查询性能调优实战
【10月更文挑战第27天】本文深入探讨了MySQL的索引策略和查询性能调优技巧。通过介绍B-Tree索引、哈希索引和全文索引等不同类型,以及如何创建和维护索引,结合实战案例分析查询执行计划,帮助读者掌握提升查询性能的方法。定期优化索引和调整查询语句是提高数据库性能的关键。
82 1