MySQL 文档说:
When the LOAD DATA INFILE statement finishes, it returns an information string in the following format:
Records: 1 Deleted: 0 Skipped: 0 Warnings: 0
现在,我想在通过 Java 代码执行 Load Data Infile 时获取此信息字符串。这是必需的,因为我必须计算向表中插入的次数,以确保我们不会遗漏任何记录。请注意,我的 Java 代码是可以的,我需要知道如何捕获此字符串。
最佳答案
关键是使用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);
关于java - 捕获MySQL的信息字符串输出-用Java编码时加载数据INFILE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30863918/