mysql批量插入

Posted 北骁蚁

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mysql批量插入相关的知识,希望对你有一定的参考价值。

有多种方式

其中效率高 要求低的方式 是 把sql拼接出来 后一次性commit;

eg:

public int insertBatch(List<PeccDetailModel> list) {
return super.insert("com.hshc.web.pec.dao.PeccDetailDao.insertBatch",list);
}

<insert id="insertBatch">

insert ignore into table_
(
id, pecc_id,
pecc_no,
plate_no,
infomation_code,
pecc_time,
pecc_addr,
pecc_reason,
pecc_amount,
status,
department,
pecc_score,
pecc_code,
violation_code,
archive_no,
phone,
excute_location,
excute_department,
category, late_fees,
basis_punishment,
illegal_entry,
location_id,
pecc_location_code,
location_name,
source_id,
record_type,
handle_time,
parties, version,
create_emp,
create_emp_id,
create_time,
modify_emp_id,
modify_emp,
modify_time,
vin_no,
engine_no,
city_id
)
values
<foreach collection="list" separator="," item="item">
(
#{item.id},
#{item.peccId},
#{item.peccNo},
#{item.plateNo},
#{item.infomationCode},
#{item.peccTime},
#{item.peccAddr},
#{item.peccReason},
#{item.peccAmount},
#{item.status},
#{item.department},
#{item.peccScore},
#{item.peccCode},
#{item.violationCode},
#{item.archiveNo},
#{item.phone},
#{item.excuteLocation},
#{item.excuteDepartment},
#{item.category},
#{item.lateFees},
#{item.basisPunishment},
#{item.illegalEntry},
#{item.locationId},
#{item.peccLocationCode},
#{item.locationName},
#{item.sourceId},
#{item.recordType},
#{item.handleTime},
#{item.parties},
#{item.version},
#{item.createEmp},
#{item.createEmpId},
#{item.createTime},
#{item.modifyEmpId},
#{item.modifyEmp},
#{item.modifyTime},
#{item.vinNo},
#{item.engineNo},
#{item.cityId}
)
</foreach>
</insert>

























































































以上是关于mysql批量插入的主要内容,如果未能解决你的问题,请参考以下文章

MySql批量插入与唯一索引问题

mysql批量插入数据

mysql批量插入数据

向mysql中批量插入数据的性能分析

mybatis mysql 批量插入

MySQLのmybatis批量插入数据