mybatis执行批量更新batch update 的方法(oracle,mysql)
2016-01-05 21:32
811 查看
oracle和mysql数据库的批量update在mybatis中配置不太一样:
oracle数据库:
<update id="batchUpdate" parameterType="java.util.List">
<foreach collection="list" item="item" index="index" open="begin" close="end;" separator=";">
update test
<set>
test=${item.test}+1
</set>
where id = ${item.id}
</foreach>
</update>mysql数据库:
mysql数据库采用一下写法即可执行,但是数据库连接必须配置:&allowMultiQueries=true
例如:jdbc:mysql://192.168.1.236:3306/test?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true
Jdbc Url 中设置allowMultiQueries=true时,可以允许一次执行多条sql(通过分号分割),
oracle数据库:
<update id="batchUpdate" parameterType="java.util.List">
<foreach collection="list" item="item" index="index" open="begin" close="end;" separator=";">
update test
<set>
test=${item.test}+1
</set>
where id = ${item.id}
</foreach>
</update>mysql数据库:
mysql数据库采用一下写法即可执行,但是数据库连接必须配置:&allowMultiQueries=true
例如:jdbc:mysql://192.168.1.236:3306/test?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true
<update id="batchUpdate" parameterType="java.util.List"> <foreach collection="list" item="item" index="index" open="" close="" separator=";"> update test <set> test=${item.test}+1 </set> where id = ${item.id} </foreach> </update>
Jdbc Url 中设置allowMultiQueries=true时,可以允许一次执行多条sql(通过分号分割),
相关文章推荐
- Oracle 12c RMAN备份文档
- Oracle学习之shared pool及sga的大小的设置
- 卸载oracle
- MySQL与Oracle的区别
- Oracle表 序列 约束 视图 索引的操作
- oracle 递归查询的例子
- oracle查询指定月份数据
- oracle 字符串截取
- ORA-01940
- oracle 开发 第02章 查询
- 批量move table\者重建索引
- ORACLE水位线讲解
- Oracle 12c: RMAN restore/recover pluggable database
- C#连接Oracle数据库的简单应用
- Oracle连接字符串总结
- oracle数据库表空间
- C# 连接 Oracle 的几种方式
- oracle 删除用户,提示“无法删除当前已连接的用户”
- oracle数据库之快速精简教程
- 如何提高oracle的查询速度(详解)