ImportMain.java
1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package com.glsx.bzi.logistmap;
import com.glsx.conf.ConfigurationManager;
import com.glsx.connection.MysqlConn;
import java.io.*;
import java.sql.Connection;
/**
* 将数据从文件中导入mysql
*/
public class ImportMain {
public static void main(String[] args) throws IOException {
long bgnTime = System.currentTimeMillis();
// Connection mysqlConn = MysqlConn.getConnection(ConfigurationManager.getProperty("mysql_dev_login"));
Connection mysqlConn = MysqlConn.getConnection(ConfigurationManager.getProperty("mysql_prd_login"));
// MysqlConn.executeUpdate(mysqlConn, "TRUNCATE TABLE device_mapping");
InputStreamReader read = new InputStreamReader(new FileInputStream(new File("data/logistmap/result")));
BufferedReader br = new BufferedReader(read);
String lineTxt = null;
// String trunSql = "truncate table device_mapping";
// MysqlConn.executeUpdate(mysqlConn,trunSql);
String sql = "insert into device_mapping(type,devType,fakeSn,realSn,activeTime,merchant_id,merchant_name) values ";;
String values = "";
int index = 0;
while((lineTxt = br.readLine()) != null) {
String[] split = lineTxt.split("\\,");
values += "(" + split[3] + "," + split[2] + ",'" + split[0] + "','" +
split[1] + "','" + split[4] + "'," + split[7] + ",'" + split[8] + "'),";
if (++index % 5000 == 0) {
MysqlConn.executeUpdate(mysqlConn, sql + values.substring(0, values.length()-1));
values = "";
}
}
MysqlConn.executeUpdate(mysqlConn, sql + values.substring(0, values.length()-1));
System.out.println("total size is " + index);
MysqlConn.close(mysqlConn);
System.out.println("The job total cost " + (System.currentTimeMillis()-bgnTime)/1000 + "s");
}
}