文章目录

平常心博客

平常心的日常积累

标签: Druid (1)

【转载】MySql+Mybatis+Druid在一个Mybatis中执行多条SQL 有更新!

做一个批量update的操作 ,sqlmap如下:

<update id="updateBatch" parameterType="java.util.List">  
  <foreach collection="list" item="item" index="index" open="" close="" separator=";">  
    update devicebdtoken   
	 <set>  
	   access_token=#{item.accessToken}  
	 <set>  
    where device_id = #{item.deviceId}  
  <foreach>  
<update>

在不设置的情况下会报错:

Caused by: java.sql.SQLException: sql injection violation, multi-statement not allow : update device_bd_token 
                 SET access_token=? 
                where device_id = ?
          ; 
                update device_bd_token 
                 SET access_token=? 
                where device_id = ?
	at 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)

刚开始以为是连接数据库的url上没有加上支持批量的参数,然后就改了下:

jdbc.url=jdbc:mysql://192.168.11.107:3306/alarm_db?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8

结果还是同样的错误!但是在命令行直接执行又是没问题的,这就很奇怪了!

浏览次数:1633783   文章总数:80   评论总数:6   当前访客:3
平常心博客 © 2018 ×
¥
每天领支付宝红包
Powered by B3log 开源Solo 2.4.0