Re: How to use "load data local infile"statement from inputstream?
Posted by: Todd Farmer
Date: April 28, 2010 10:38AM

You need to cast the Statement to com.mysql.jdbc.Statement. Once you do that, you can call setLocalInfileInputStream, which effectively bypasses the filename you provide in the actual LOAD DATA command:

Class.forName("com.mysql.jdbc.Driver");

String url =
"jdbc:mysql://" + sqlhost + ":"+ sqlport + "/test";

con = DriverManager.getConnection(url,sqlUser, sqlPasswd);

con.createStatement().execute("DROP TABLE IF EXISTS testloaddata");
con.createStatement().execute("CREATE TABLE testloaddata(a VARCHAR(10), b INT)");

com.mysql.jdbc.Statement s = (com.mysql.jdbc.Statement) con.createStatement();

s.setLocalInfileInputStream(new mockIS("test\t1\ntesting\t2\n"));
s.execute("LOAD DATA LOCAL INFILE 'test.sql' INTO TABLE testloaddata");

ResultSet rs = con.createStatement().executeQuery("SELECT * FROM testloaddata");

while (rs.next()){
System.out.println("a: " + rs.getString(1) + ", b: " + rs.getInt(2) );
}

Options: ReplyQuote


Subject
Written By
Posted
Re: How to use "load data local infile"statement from inputstream?
April 28, 2010 10:38AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.