My code is very simple. but after running executeBatch() only 1 row gets into the DB.
The code is below:
//INSIDE LOOP:
{
ps = conn.prepareStatement("INSERT INTO NK_EVENT_DATA VALUES(?,?,?,?,?,?,?);
// setting bind variable values
ps.setLong(1, ed_fi_uid);
ps.setString(2 , ed_date);
ps.setString(3, ed_hash_key);
ps.setLong(4 , ed_et_uid);
ps.setLong(5, ed_etn_uid);
ps.addBatch();
}
//LOOP ENDS
ps.executeBatch();
However, only one record gets inserted instead of the 5 records.
You are creating a new PreparedStatement in each loop. Each statement only gets one batch added to it, and only the last statement gets executed.
Move ps = conn.prepareStatement("INSERT INTO NK_EVENT_DATA VALUES(?,?,?,?,?,?,?);
outside the loop.
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