生成CSV文件后再将CSV文件导入到mysql

1、生成CSV

jar包:http://pan.baidu.com/s/1xIL26

String csvFilePath = "d:\\test.csv";
CsvWriter wr =new CsvWriter(csvFilePath,',',Charset.forName("UTF-8"));
for(int i=;i<;i++)
{
String[] contents = {String.valueOf(i),"测试"+i};
wr.writeRecord(contents);
}
wr.close();

2、导入到mysql

String url = "jdbc:mysql://127.0.0.1/test?useUnicode=true&characterEncoding=UTF-8&rewriteBatchedStatements=true";
String user = "root";
String password = "";
Connection conn= DriverManager.getConnection(url,user,password);
conn.setAutoCommit(false);
PreparedStatement pstmt = conn.prepareStatement("load data local infile 'd:/test.csv' into table test fields terminated by ','");
pstmt.execute();
conn.commit();
上一篇:freeRTOS中文实用教程3--中断管理之计数信号量


下一篇:DOM节点的基础操作