MySQL的批处理
MySQL默认是关闭批处理的,所以我们在默认状态下(批处理未打开)向数据库中存入10000条数据,核心代码如下:
package cn.itcast.demo5;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import org.junit.Test;
import cn.itcast.demo3.JdbcUtils;
public class Demo5 {
@Test
public void fun5() throws SQLException {
/*
* pstmt:
* > 添加参数到批中
* > 执行批!
*/
Connection con = JdbcUtils.getConnection();
String sql = "INSERT INTO t_stu VALUES(?,?,?,?)";
PreparedStatement pstmt = con.prepareStatement(sql); // 疯狂的添加参数
for(int i = 0; i < 10000; i++) {
pstmt.setInt(1, i+1);
pstmt.setString(2, "stu_" + i);
pstmt.setInt(3, i);
pstmt.setString(4, i%2==0?"男":"女");
pstmt.addBatch();//添加批!这一组参数就保存到集合中了。
}
long start = System.currentTimeMillis();
pstmt.executeBatch();//执行批!
long end = System.currentTimeMillis();
System.out.println(end - start);
}
}
上述程序执行结束耗费时间412764MS
这是打开MySQL的批处理,打开方式:
将MySQL参数 url=jdbc:mysql://localhost:3306/exam
改为 url=jdbc:mysql://localhost:3306/exam?rewriteBatchedStatements=true
再次执行程序,耗时301MS,速度快了1000倍以上!
MySQL的批处理的更多相关文章
- MySQL 8 批处理模式
shell> mysql -h host -u user -p < batch-file 强制执行脚本,即使某些语句参数错误,可以添加 --force 参数 如果MySQL运行在Windo ...
- 备份mysql的批处理命令
需要工具mysqldump.exe的支持,安装mysql默认是带此工具的 批处理命令 set NOW_TIME_HH=%time:~0,2% if "%NOW_TIME_HH%" ...
- Mysql 冷备份批处理
@Rem Generate today date @echo wscript.echo dateadd("d",0,date)>GetOldDate.vbs @for /f ...
- MySQL批处理SQL语句
MySQL 支持批处理的模式运行一批SQL语句,以下的样例就是实验MySQL怎样在windows下批处理运行SQL语句. create table test(id int,name varchar(2 ...
- mysql 在创建批处理脚本日志表信息
mysql在批处理脚本通过存储过程如下所示创建日志信息表: drop PROCEDURE if EXISTS reqSp; DELIMITER // create procedure reqSp(sT ...
- Mysql的预编译和批处理
MySQL的预编译功能 预编译的好处 大家平时都使用过JDBC中的PreparedStatement接口,它有预编译功能.什么是预编译功能呢?它有什么好处呢? 当客户发送一条SQL语句给服务器后,服务 ...
- MySql 批处理
1. 批处理 批处理只针对更新(增,删,改)语句. MySql 的批处理默认是关闭的, 需要在 url 中配置参数: jdbc:mysal://localhost:3306/mydb1?rewrite ...
- SQL语句大全(mysql,sqlserver,oracle)
SQL语句大全 --语句功能--数据操作SELECT --从数据库表中检索数据行和列-selectINSERT --向数据库表添加新数据行-insertDELETE --从数据库表中删除数据行-del ...
- mysql 使用说明-3
3.4 Getting Information About Databases and Tables 获取数据库和表格的信息 如果你忘记了数据库或者表格的名字怎么办?或者给定的表格的结构怎么办?(例如 ...
随机推荐
- Java for LeetCode 232 Implement Queue using Stacks
Stack<Integer> stack=new Stack<Integer>(); public void push(int x) { stack.push(x); } // ...
- Java for LeetCode 221 Maximal Square
Given a 2D binary matrix filled with 0's and 1's, find the largest square containing all 1's and ret ...
- C#关于new的用法
1.运算符就是在实例化一个类的时候(运算符的用法) A a=new A(); 2.new 约束指定泛型类声明中的任何类型参数都必须有公共无参数构造函数.当泛型类创建类型的新实例时,将此约束应用于类型参 ...
- linq lanbda表达式的用法
1. 查询Student表中的所有记录的Sname.Ssex和Class列.select sname,ssex,class from studentLinq: from s in Student ...
- yii 多表联合查询的几种方法
yii多表联合查询, 第一种,用command,自己拼接sql语句执行查询 第二种,用AR,model需继承下面的ar,执行queryall或queryrow方法 <?php //applica ...
- 单独编译osgQt模块 Qt moc
从alphapixel网站下载了OSG3.0.1VS2010x64版本的库,但是里面不包括osgQt模块,于是得自己编译 *************osgQtx64.zip工程文件可以去本博客园的“文 ...
- October 12th 2016 Week 42nd Wednesday
Passion is momentary; love is enduring. 激情短暂,真爱长久. What is love? And what is real love? We are alway ...
- 多线程编程1 - NSThread
每个iOS应用程序都有个专门用来更新显示UI界面.处理用户的触摸事件的主线程,因此不能将其他太耗时的操作放在主线程中执行,不然会造成主线程堵塞(出现卡机现象),带来极坏的用户体验.一般的解决方案就是将 ...
- kmp
#include <bits/stdc++.h> #define MAXN 100000 using namespace std; string a, b; int next[MAXN]; ...
- hdu 2057 A+B
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2057 For each test case,print the sum of A and B in h ...