MySQL文档说:
LOAD DATA INFILE语句完成后,将以下列格式返回信息字符串: 记录:1删除:0跳过:0警告:0
现在,当我通过Java代码执行Load时,我希望得到这个信息字符串。这是必要的,因为我必须统计表中插入的数量,以确保我们不会遗漏任何记录。注意,我的Java代码很好,我需要知道如何捕获这个字符串。
发布于 2016-09-17 16:42:44
关键是要使用executeUpdate();
尝尝这个
Connection con = DriverManager.getConnection("jdbc:mysql://localhost/foobar", "root", "password");
Statement stmt = con.createStatement();
String sql =
"load data infile 'c:/temp/some_data.txt' \n" +
" replace \n" +
" into table prd \n" +
" columns terminated by '\\t' \n" +
" ignore 1 lines";
int rows = stmt.executeUpdate(sql);
System.out.println("Rows: " + rows);发布于 2015-06-16 09:42:47
下面的工作将通过JDBC完成。注意,要使用,您需要超级用户特权。在加载数据本地信息时不需要的
Connection con = DriverManager.getConnection("jdbc:mysql://localhost/foobar", "root", "password");
Statement stmt = con.createStatement();
String sql =
"load data infile 'c:/temp/some_data.txt' \n" +
" replace \n" +
" into table prd \n" +
" columns terminated by '\\t' \n" +
" ignore 1 lines";
stmt.execute(sql);https://stackoverflow.com/questions/30863918
复制相似问题