Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between executeBatch() and executeLargeBatch() while using PreparedStatement

I am confused about when to use executeBatch() and executeLargeBatch(). I went through the Java documents and the only difference I found is:

executeLargeBatch() should be used when the returned row count may exceed Integer.MAX_VALUE.

I replaced executeBatch() with executeLargeBatch() but haven't found any performance improvements.

Is handling Integer.MAX_VALUE the only purpose? Is there any performance advantage in one over the other?

like image 536
MBR Avatar asked Mar 11 '15 10:03

MBR


1 Answers

Your quoted difference is the difference: executeBatch returns int[] to return the counts of each update. executeLargeBatch returns long[] to return the counts of each update. Hence the documentation saying to use the latter if the count may exceed the capacity of int. E.g., they're the batch equivalents of executeUpdate (returns int) and executeLargeUpdate (returns long).

I wouldn't expect a performance difference of any significance; it's just a matter of not overflowing the int if you're potentially updating more than 2,147,483,647 rows.

like image 165
T.J. Crowder Avatar answered Sep 30 '22 09:09

T.J. Crowder