I want to use QueryRunner to perform an insert of an ArrayList. The only information I am finding online is for inserting one Object[]. Something along the lines of:
qr.update("insert into MyTable (param1,param2,param3) values (?,?,?)",
new Object[] { str1, str2, str3});
I would obviously like to avoid having to loop through an entire ArrayList and insert one index at a time due to the number of rows to be inserted being unknown each time.
I just wanted to see if anyone has done this. A query returns a List, so I do not see why I cannot insert a List. Any suggestions are appreciated. Thanks.
I know this is old but I was looking for info about Apache Commons DBUtils QueryRunner and came across this... For future reference you can:
First convert the ArrayList into an Object[][]:
Object[][] params = null;
params = listOfObjectArrays.toArray(params);
Then pass params
to the batch method on the QueryRunner (returns int[]):
qr.batch("insert into MyTable (param1,param2,param3) values (?,?,?)", params);
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