try (BufferedReader br = new BufferedReader(new FileReader("LoadData.txt"))){
final Connection connection = DriverManager.getConnection("jdbc:mysql://ipAddress:port/database?user=username&password=password&useServerPrepStmts=false&rewriteBatchedStatements=true");
String sCurrentLine;
final PreparedStatement ps = connection.prepareStatement("insert ignore into emails (email) value (?)");
int count = 0;
final int batchSize = 1000;
while ((sCurrentLine = br.readLine()) != null) {
ps.setString(1, sCurrentLine);
ps.addBatch();
if(++count % batchSize == 0) {
ps.executeBatch();
}
}
ps.executeBatch();
ps.close();
connection.close();
} catch (final IOException e) {
e.printStackTrace();
}
即使使用上面的代码,批量插入也非常慢,每1000行需要几分钟。有谁知道什么是错的?
答案 0 :(得分:1)
在将来与其他人混淆的情况下发布答案:
我的SQL查询有关键字" 值"。关键字必须为" 值"使批量插入工作。