码迷,mamicode.com
首页 > 数据库 > 详细

mysql中load data Infile运用

时间:2014-07-24 17:39:26      阅读:257      评论:0      收藏:0      [点我收藏+]

标签:mysql load data infi   批量插入   

速度比insert要快20倍。共享一下java程序操作。
package com.mysql.csv;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class Competition {
	 static Connection  conn = null;
     static String driver = "com.mysql.jdbc.Driver";
     static String url = "jdbc:mysql://127.0.0.1:3306/nerd_1"; 
     public static void main(String[] args) throws ClassNotFoundException, SQLException {
    	 Class.forName(driver);
         conn =  DriverManager.getConnection(url, "root", "1234");
         String sql = "LOAD DATA INFILE 'E://baidu//cp9.csv' REPLACE INTO TABLE baidu_34000_0_competition CHARACTER SET utf8 FIELDS TERMINATED BY ',' ENCLOSED BY '\"' LINES TERMINATED BY '\r\n' ignore 1 lines";
         PreparedStatement  pstmt = conn.prepareStatement(sql);
	     pstmt.execute();  
	     conn.close(); 
	} 
}
批量插入需要条件具体可参考文档:http://dev.mysql.com/doc/refman/5.1/zh/sql-syntax.html#load-data

mysql中load data Infile运用,布布扣,bubuko.com

mysql中load data Infile运用

标签:mysql load data infi   批量插入   

原文地址:http://blog.csdn.net/u012516914/article/details/38085199

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!