Created
February 22, 2015 18:25
-
-
Save pgtwitter/ac0865d1a120e5bef0e3 to your computer and use it in GitHub Desktop.
setLocalInfileInputStraemを用いたLOAD DATA LOCAL INFILE (MySQL) (参考 http://d.hatena.ne.jp/sh2/20090528 )
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
byte[] buf= {}; | |
Connection conn = DriverManager.getConnection(JDBC_URL, JDBC_USER, JDBC_PASS); | |
//conn.setAutoCommit(false); | |
Statement stmt = conn.createStatement(); | |
String sql = "LOAD DATA LOCAL INFILE '' INTO TABLE thetable" | |
+ " FIELDS TERMINATED BY ',' ENCLOSED BY '\"' ESCAPED BY '\"'" | |
+ " LINES TERMINATED BY '\n'"; | |
InputStream is = new ByteArrayInputStream(buf); | |
((com.mysql.jdbc.Statement) stmt).setLocalInfileInputStream(is); | |
stmt.execute(sql); | |
//conn.commit(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment