Mybatis 大数据量的批量insert解决方案

本文介绍了在使用Mybatis进行7000+数据量批量插入时遇到的错误及解决方法。通过源码分析发现,默认的Simple执行器为每个语句创建新的预处理语句,可能导致效率低下和超时。尝试切换到ExecutorType.BATCH并分批处理数据,但在实际操作中仍然出现错误。最终,通过在同一事务内分批次commit解决了问题,成功插入7728条数据,总耗时约10秒。
摘要由CSDN通过智能技术生成

前言

通过Mybatis做7000+数据量的批量插入的时候报错了,error log如下:

   ,  
('G61010352', 
'610103199208291214',   
'学生52', 
'G61010350',
'610103199109920192',
'学生50',
'07',
'01',
'0104',
' ',
0,
' ',
' ',
current_timestamp,
current_timestamp
) 被中止,呼叫 getNextException 以取得原因。

    at org.postgresql.jdbc2.AbstractJdbc2Statement$BatchResultHandler.handleError(AbstractJdbc2Statement.java:2743)
    at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:411)
    at org.postgresql.jdbc2.AbstractJdbc2Statement.executeBatch(AbstractJdbc2Statement.java:2892)
    at com.alibaba.druid.filter.FilterChainImpl.statement_executeBatch(FilterChainImpl.java:2596)
    at com.alibaba.druid.wall.WallFilter.statement_executeBatch(WallFilter.java:473)
    at com.alibaba.druid.filter.FilterChainImpl.statement_executeBatch(FilterChainImpl.java:2594)

    at com.alibaba.druid.filter.FilterAdapter.statement_executeBatch(FilterAdapter.java:2474)
    at com.alibaba.druid.filter.FilterEventAdapter.statement_executeBatch(FilterEventAdapter.java:279)
    at com.alibaba.druid.filter.FilterChainImpl.stateme
评论 19
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值