前言
提示:这里可以添加本文要记录的大概内容:
这里SQL样式是批量插入
示例:
insert into table_name(字段1,字段2,字段3…)
select t1.字段1,t2.字段2,t3.字段3… from
(<foreach collection=“list” item="item sparator=“union all”>
select #{item.字段1},#{item.字段2},#{item.字段3}…from dual
) t1
提示:以下是本篇文章正文内容,下面案例可供参考
主要步骤
1.mysql的连接url加上以下参数:
String url = “jdbc:mysql://localhost:3306/User?rewriteBatched-Statements=true&useServerPrepStmts=false”;
两个参数分别是开启批量处理和预编译
2.使用SqlSessionFactory对象
二、话不多说直接上代码
总结
实测10万条数据耗时55秒。