for (int i = 0; i < 100000; i++) {
dbHelper.insert("INSERT aaa(name) Values ('1')");
}

运行时间==780450ms

conn = getConn();
// JAVA默认为TRUE,我们自己处理需要设置为FALSE,并且修改为手动提交,才可以调用rollback()函数
conn.setAutoCommit(false);
st = conn.createStatement();
long start = System.currentTimeMillis();
for (int i = 0; i < 100000; i++) {
st.execute("INSERT bbb(name) Values ('1')");
}
// 事务提交
conn.commit();
long end = System.currentTimeMillis();
System.out.println("运行时间==" + (end - start) + "ms");

运行时间==21484ms

conn = getConn();
// JAVA默认为TRUE,我们自己处理需要设置为FALSE,并且修改为手动提交,才可以调用rollback()函数
conn.setAutoCommit(false);
st = conn.createStatement();
long start = System.currentTimeMillis();
for (int i = 0; i < 100000; i++) {
st.addBatch("INSERT ccc(name) Values ('1')");
}
st.executeBatch();
// 事务提交
conn.commit();

运行时间==21524ms

在mysql链接后加上如下参数,代码和上面的完全相同,结果速度快了很多

&rewriteBatchedStatements=true

运行时间==8216ms

而我在第二种方法的连接上加上&rewriteBatchedStatements=true,结果运行结果和原来相差无几

运行时间==21538ms

参考链接:

介绍MySQL Jdbc驱动的rewriteBatchedStatements参数

java 批量插入10万条数据的更多相关文章

  1. MariaDB(MySql)使用储存过程和随机函数插入10万条数据

    ))default charset =utf8; #定义一个随机切割字符串的函数 delimiter // create function randStr() ) begin ) default 'A ...

  2. 最短时间(几秒内)利用C#往SQLserver数据库一次性插入10万条数据

    用途说明: 公司要求做一个数据导入程序,要求将Excel数据,大批量的导入到数据库中,尽量少的访问数据库,高性能的对数据库进行存储.于是在网上进行查找,发现了一个比较好的解决方案,就是采用SqlBul ...

  3. 绝对干货,教你4分钟插入1000万条数据到mysql数据库表,快快进来

    我用到的数据库为,mysql数据库5.7版本的 1.首先自己准备好数据库表 其实我在插入1000万条数据的时候遇到了一些问题,现在先来解决他们,一开始我插入100万条数据时候报错,控制台的信息如下: ...

  4. 插入1000万条数据到mysql数据库表

    转自:https://www.cnblogs.com/fanwencong/p/5765136.html 我用到的数据库为,mysql数据库5.7版本的 1.首先自己准备好数据库表 其实我在插入100 ...

  5. Mvc+Dapper+存储过程分页10万条数据

    10万条数据采用存储过程分页实现(Mvc+Dapper+存储过程) 有时候大数据量进行查询操作的时候,查询速度很大强度上可以影响用户体验,因此自己简单写了一个demo,简单总结记录一下: 技术:Mvc ...

  6. Mysql慢查询开启和查看 ,存储过程批量插入1000万条记录进行慢查询测试

    首先登陆进入Mysql命令行  执行sql      show variables like 'slow_query%';  结果为OFF 说明还未开启慢查询 执行sql     show varia ...

  7. 教你如何6秒钟往MySQL插入100万条数据!然后删库跑路!

    教你如何6秒钟往MySQL插入100万条数据!然后删库跑路! 由于我用的mysql 8版本,所以增加了Timezone,然后就可以了 前提是要自己建好库和表. 数据库test, 表user, 三个字段 ...

  8. 使用hibernate在5秒内插入11万条数据,你觉得可能吗?

    需求是这样的,需要查询某几个表的数据,然后插入到另外一个表. 一看到需求,很多人都会用hibernate去把这些数据都查询出来,然后放到list中, 然后再用for循环之类的进行遍历,一条一条的取出数 ...

  9. Delphi 操作SQL 插入一万条数据 三种方式速度测试

    unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms ...

随机推荐

  1. HDOJ 1017 A Mathematical Curiosity

    Problem Description Given two integers n and m, count the number of pairs of integers (a,b) such tha ...

  2. bzoj 1056 [HAOI2008]排名系统(1862 [Zjoi2006]GameZ游戏排名系统)

    1056: [HAOI2008]排名系统 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1854  Solved: 502[Submit][Statu ...

  3. mergeIDE

    Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\CriticalDe ...

  4. @RestController

    /* * Copyright 2002-2014 the original author or authors. * * Licensed under the Apache License, Vers ...

  5. Citrix 服务器虚拟化之十八 桌面虚拟化之部署MCS随机桌面池

    Citrix 服务器虚拟化之十八  桌面虚拟化之部署MCS随机桌面池 完成桌面模版的制作后,可以开始虚拟桌面池的发布 说明: 环境基于实验十七 1.登录DC服务器创建一个组织单位名为Citrix,然后 ...

  6. php 中的$argv与$argc

    例如 php test.php as a joke print_r($argv); echo $argc; print_r($argv); array_shift($argv); echo $argc ...

  7. python_安装工具easy_install和pip

    前言 用python就必须知道easy_install和pip这两个东西啦 easy_insall提供了在线一键安装模块或包的方便方式,而pip是easy_install的改进版,提供更好的提示信息, ...

  8. requirejs2读书笔记

    If you want to do require() calls in the HTML page, then it is best to not use data-main. data-main ...

  9. UVa 340 Master-Mind Hints (优化查找&复制数组)

    340 - Master-Mind Hints Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_on ...

  10. SQL报错error:索引中丢失IN或OUT參数

    简单记录下: 今天mybatis中遇到一个错误: org.springframework.jdbc.UncategorizedSQLException: PreparedStatementCallba ...