【实践】jdbc批量插入数据】的更多相关文章

JDBC批量插入数据优化,使用addBatch和executeBatch SQL的批量插入的问题,如果来个for循环,执行上万次,肯定会很慢,那么,如何去优化呢? 解决方案:用 preparedStatement.addBatch()配合preparedStatement.executeBatch()去批量插入: 效率要比一条一条插入快近60倍. 代码: //获取要设置的Arp基准的List后,插入Arp基准表中 public boolean insertArpStandardList(List…
平时使用mysql插入.查询数据都没有注意过效率,今天在for循环中使用JDBC插入1000条数据居然等待了一会儿 就来探索一下JDBC的批量插入语句对效率的提高 首先进行建表 create table `user1`( `id` int primary key auto_increment, `phoneNumber` int not null , `indentity` int not null , `address` varchar(100), index (id,phoneNumber,…
参考文献:http://my.oschina.net/u/1452675/blog/203670 http://superjavason.iteye.com/blog/255423 /*测试批量写入数据*/ long start = System.currentTimeMillis(); DaoRecord daoRecord = new DaoRecord(); List<T> list = new ArrayList<T>(); for(int i = 1; i <= 1…
对于需要批量插入数据库操作JDBC有多重方式,本利从三个角度对Statement和PreparedStatement两种执行方式进行分析,总结较优的方案. 当前实现由如下条件: 执行数据库:Mysql 执行数据数量:10万条 执行前提:执行差入数据库钱均需要提供空表,防止数据量大造成的影响 执行方式:Statement和PreparedStatement两种方式 执行步骤开始: 1.创建表 CREATE TABLE T_PRODUCT ( ID bigint(12) NOT NULL AUTO_…
//插入很多书(批量插入用法) public void insertBooks(List<Book> book) {   final List<Book> tempBook=book;   String sql="insert into book(name,pbYear) values(?,?)";   jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter()   {    public v…
测试用的示例java代码: package com.zifeiy.test.normal; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStreamWriter; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException…
批量插入数据 @Test public void testInsert() throws Exception { Connection conn = null; PreparedStatement ps = null; try { conn = JdbcUtils.getConnection(); String sql = "insert into blobtest (username,password,photo) values (?,?,?)"; ps = conn.prepare…
前言:做一个数据同步项目,要求:同步数据不丢失的情况下,提高插入性能. 项目DB框架:Mybatis.DataBase:Oracle. ---------------------------------------------------------------------------- 批量插入数据方式: 一.Mybatis 全局设置批处理: 二.Mybatis 局部设置批处理: 三.Mybatis foreach批量插入: ①SELECT UNION ALL: ②BEGIN INSERT I…
转自http://www.cnblogs.com/fnz0/p/5713102.html 不知道自己什么时候才有这种钻研精神- -. 1      背景 系统中需要批量生成单据数据到数据库表,所以采用批量插入数据库的方式.由于系统中ORM操作集成使用的是Mybatis来完成的. 在Mybatis中操作一般使用批量插入的方式如下: <insert id="insertBatch" parameterType="java.util.List"  > inse…
//批量添加20000条数据用时8秒. try {    String url = "jdbc:oracle:thin:@IP:1521:orcl"; // orcl为数据库的SID    String user = "oracle";    String password = "oracle";    StringBuffer sql = new StringBuffer();    sql.append("insert into e…