Skip to content

Instantly share code, notes, and snippets.

@pgtwitter
Created February 22, 2015 18:25
Show Gist options
  • Save pgtwitter/ac0865d1a120e5bef0e3 to your computer and use it in GitHub Desktop.
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 )
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