mybaties中语句为:
<update id="batchUpdate" parameterType="java.util.List">
        <foreach collection="list" item="item" index="index" open="begin" close=";end;" separator=";" > 
            update ID
            <set>       
                 id_type=${item.idType}
            </set>
            where id = #{item.id}
        </foreach>
    </update>
报错如下:org.springframework.jdbc.UncategorizedSQLException: 
### Error updating database.  Cause: java.sql.SQLException: sql injection violation, class com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleBlockStatement not allow : begin   
            update ID
           set
                  id_type='rr'
            where id = 17
         ;  
            update ID
           set
                  id_type='rs'
            where id = 18
         ;end;
### SQL: begin                update ID            set                   id_type='rr'             where id = 17          ;               update ID            set                   id_type='rs'             where id = 18          ;end;
sql语句放到pl/sql 里可以直接用,为什么这里会报错啊,各位大神,有知道的吗?

解决方案 »

  1.   

    你要更新多列吗? 那不用 foreach 的;
      

  2.   

    现在的jsp都能直接操作数据库了, 这么先进了吗,安全方面也能支持吗
    没用这么高端的技术,猜了一下可能是如下原因:1、表名叫ID,字段名也叫id,这个ID是oracle关键字,虽然说可以这么搞,但是谁知道加上你这个技术以后会不是有问题,你可以试试换个表名,换个字段名。
    2、看看是不是事务处理的配置有问题。
    除了这两个,,,其他想不到了。
      

  3.   

    哦哦,看错了,是mybaties配置,看成JSP了
      

  4.   

    这玩意怎么回复啊。。
    是传来一个list参数,根据这个list更新表里的数据看网上别人说foreach是这么用的,我的就报错,没找到原因
      

  5.   


    是传来一个list参数,根据这个list更新表里的数据看网上别人说foreach是这么用的,我的就报错,没找到原因
      

  6.   

    你的预期的 sql ,应该什么样的呢?
      

  7.   

    多条update执行  大概就是这样
    begin   
                update ID
               set
                      id_type='rr'
                where id = 17
             ;  
                update ID
               set
                      id_type='rs'
                where id = 18
             ;end;
      

  8.   

    mybaties 中只能执行一条语句,要要执行多次 DAO ;或者拼接成 update ID 
    set id_type= decode(id,18,'rs',17,'rr')
    where id in (18,17)这样的;
      

  9.   

    嗯,那update没有foreach的用法吗,之前用insert语句的时候可以用foreach
      

  10.   

    insert 你是拼接的是多个 select 做union all 操作吧?
      

  11.   

    多个 select 进行 union all 操作,其实就是一条语句,你这个 update 可以参考  8# 这个写法;