MyBatis中如何一次执行多条语句(使用mysql数据库)


解决办法不外乎有三个:1、多条sql分批执行;2、存储过程或函数调用;3、sql批量执行。

 

MyBatis中如何一次执行多条语句(使用mysql数据库):

1、修改数据库连接参数加上allowMultiQueries=true,如:

hikariConfig.security.jdbcUrl=jdbc:mysql://xx.xx.xx:3306/xxxxx?characterEncoding=utf-8&autoReconnect=true&failOverReadOnly=false&allowMultiQueries=true

2、直接写多条语句,用“;”隔开即可

<delete id="deleteComboInfo">  
delete from amb_pairs where id in  
<foreach collection="id.split(',')" close=")" open="(" separator="," item="item">  
#{item}  
</foreach>  
;  
  
delete from amb_pair_detail where pair_id in  
<foreach collection="id.split(',')" close=")" open="(" separator="," item="item">  
#{item}  
</foreach>  
;  
  
</delete>  

 

 


 -END-


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM