Mybatis实现Oracle批量插入

wozuiaijiahui 2014-06-10 04:52:57
之前用的SqlSessionDaoSupport,但是网上搜了下,发现getSqlSession()不能设置ExecutorType,所以又自己重写了一个类,为SqlSession设置了ExecutorType,Mapper里使用
<insert id="insertBatch" >
insert into student ( <include refid="Base_Column_List" /> )
values
<foreach collection="list" item="item" index="index" separator=",">
(null,#{item.name},#{item.sex},#{item.address},#{item.telephone},#{item.tId})
</foreach>
</insert>
会报错,ORA-00933: SQL 命令未正确结束,ORACLE应该不支持这种写法吧,然后改成这样

<insert id="insertBatch" >
<foreach collection="list" item="item" index="index" separator=",">
insert into student ( <include refid="Base_Column_List" /> )
values
(null,#{item.name},#{item.sex},#{item.address},#{item.telephone},#{item.tId})
</foreach>
</insert>
还是报错,谁遇到过这种情况,帮忙看下,多谢了,另外问下mybaits这种批量插入的方式如果用SPRING管理事物,中途插入异常会回滚吗?
...全文
1787 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
wingfly110 2016-12-10
  • 打赏
  • 举报
回复
<insert id="addByBatchToChannel" parameterType="java.util.Map" > <foreach collection="list" item="item" index="index" open="begin" close=";end;" separator=";"> insert into SSD_EMS_ALM_FILINGCHANNEL (KEYID, FILINGID, CHANNELTYPE) values (SEQ_SSD_EMS_ALM_FILINGCHANNEL.NEXTVAL, #{item.FILINGID,jdbcType=INTEGER}, #{item.CHANNELTYPE,jdbcType=INTEGER}) </foreach> </insert>
江北雪 2015-04-28
  • 打赏
  • 举报
回复
<insert id="insertBatch" > <foreach collection="list" item="item" index="index" separator=" UNION ALL "> insert into student ( <include refid="Base_Column_List" /> ) values select null,#{item.name},#{item.sex},#{item.address},#{item.telephone},#{item.tId} from dual </foreach> </insert>
wozuiaijiahui 2014-06-10
  • 打赏
  • 举报
回复
已经实现http://blog.csdn.net/sanyuesan0000/article/details/19998727,不过不支持SPRING的事物管理http://blog.csdn.net/m13321169565/article/details/7729422,在mybaits中通过preparedStatement实现批量操作会不会很麻烦,需要获取preparedStatement对象,1楼的大牛,你做批处理的时候怎么管理事物的?用mybatis自身事物管理吗?
oh_Maxy 2014-06-10
  • 打赏
  • 举报
回复
为啥不在代码里,通过preparedStatement实现批量操作呢

67,550

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧