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

本文涉及的产品
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

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


相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
3天前
|
算法 Java 数据库连接
Spring+MySQL+数据结构+集合,Alibaba珍藏版mybatis手写文档
Spring+MySQL+数据结构+集合,Alibaba珍藏版mybatis手写文档
|
4天前
|
存储 关系型数据库 MySQL
《MySQL 入门教程》第 05 篇 账户和权限,Java高并发编程详解深入理解pdf
《MySQL 入门教程》第 05 篇 账户和权限,Java高并发编程详解深入理解pdf
|
4天前
|
存储 数据可视化 前端开发
Echarts+vue+java+mysql实现数据可视化
Echarts+vue+java+mysql实现数据可视化
|
4天前
|
Java 关系型数据库 MySQL
MySql数据库级别MD5加密java MD5加密解密工具包
MySql数据库级别MD5加密java MD5加密解密工具包
|
5天前
|
XML Java 数据库连接
Java一分钟之MyBatis:持久层框架基础
【5月更文挑战第15天】MyBatis是Java的轻量级持久层框架,它分离SQL和Java代码,提供灵活的数据库操作。常见问题包括:XML配置文件未加载、忘记关闭SqlSession、接口方法与XML映射不一致、占位符使用错误、未配置ResultMap和事务管理不当。解决这些问题的关键在于正确配置映射文件、管理SqlSession、避免SQL注入、定义ResultMap以及确保事务边界。遵循最佳实践可优化MyBatis使用体验。
15 2
Java一分钟之MyBatis:持久层框架基础
|
5天前
|
Java 数据挖掘 BI
Java医院绩效考核系统源码B/S+avue+MySQL助力医院实现精细化管理
医院绩效考核系统目标是实现对科室、病区财务指标、客户指标、流程指标、成长指标的全面考核、分析,并与奖金分配、学科建设水平评价挂钩。
32 0
|
5天前
|
SQL Java
【JAVA进阶篇教学】第九篇:MyBatis-Plus用法介绍
【JAVA进阶篇教学】第九篇:MyBatis-Plus用法介绍
|
5天前
|
Java 关系型数据库 MySQL
【JAVA进阶篇教学】第八篇:Java链接MySql数据库异常
【JAVA进阶篇教学】第八篇:Java链接MySql数据库异常
|
5天前
|
SQL Java 关系型数据库
【JAVA基础篇教学】第十六篇:Java连接和操作MySQL数据库
【JAVA基础篇教学】第十六篇:Java连接和操作MySQL数据库
|
3天前
|
关系型数据库 MySQL API
实时计算 Flink版产品使用合集之可以通过mysql-cdc动态监听MySQL数据库的数据变动吗
实时计算Flink版作为一种强大的流处理和批处理统一的计算框架,广泛应用于各种需要实时数据处理和分析的场景。实时计算Flink版通常结合SQL接口、DataStream API、以及与上下游数据源和存储系统的丰富连接器,提供了一套全面的解决方案,以应对各种实时计算需求。其低延迟、高吞吐、容错性强的特点,使其成为众多企业和组织实时数据处理首选的技术平台。以下是实时计算Flink版的一些典型使用合集。
26 0