Somehow my MySQL Inserts are really slow. Even when I use "Batch-Inserts". About 50 inserts take up to 2000ms.. Is this normal or is there a way to improve my code?
String sql = "INSERT INTO wlw ( wlw_level, wlw_name, wlw_url, wlw_processing, wlw_finished, wlw_source )"
+ "VALUES(?, ?, ?, ?, ?, ?)";
PreparedStatement preparedStatement = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
for(QueryStore qs : QueryStore) {
preparedStatement.setInt(1, qs.level);
preparedStatement.setString(2, qs.anchor);
preparedStatement.setString(3, qs.url);
preparedStatement.setInt(4, qs.processing);
preparedStatement.setInt(5, qs.finished);
preparedStatement.setLong(6, qs.id);
preparedStatement.addBatch();
System.out.println("Adding URL: " + qs.url);
}
System.out.println("Start saving ...");
long then = System.currentTimeMillis();
preparedStatement.executeBatch();
long now = then - System.currentTimeMillis();
System.out.println("SAVING END - Took me " + now + "ms");
Thanks for any suggestions!!
Try adding rewriteBatchedStatements=true to your connection parameters.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With