Here's the deal:
conn
using the DriverManager
conn.autoCommit(false);
PreparedStatement pStat = conn.prepareStatement(insert_string_with_parameter);
pStat.addBatch();
addBatch()
10000 times), I call pStat.executeBatch();
pStat.clearBatch()
right afterEven if all the above sounds good to me, this is SLOW!!!.
I have an average of only 35 records (only 8 columns total, only a technical auto-incrementing primary key and some not null constraints) per second. I calculate that it would take me a week to insert all my 20M rows...
Am I doing anything wrong?
How many rows should I try to add at every batch cycle? Are 10000 too many?
If you happen to be using MySQL with a JDBC driver around version 5.1.7 you may be affected by a bug that slows down batch inserts. Updating to 5.1.10 or later should take care of it.
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