• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Is this really a batch update

 
Ranch Hand
Posts: 316
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got this code snippet from web --



what confused me is

for (int i = 0; i < count; i++) {
batchInsert.update(new Object[] { i + 100L, "a" + i, "b" + i, null });
}


It seems it is updating the records one by one instead of at batch size. can someone explain this to me ?
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
setBatchSize(10);

Looks like the batch size is set. So after 10 updates, those 10 will be sent to the database in one call. So if you loop 5000 times then you will have 500 database calls based on that batch size.

Mark
 
Raj Ohadi
Ranch Hand
Posts: 316
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
still don't get it. So what does "update" method exactly do ? when it executes the "updte" on record 1, based on what you said, it does not immediately insert and hold it until record 10 is done with its "update" and then it inserts records 1 to 10 at same time. is that right ?
Then again what does "update" do on record 1 ?
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Raj Ohadi wrote:still don't get it. So what does "update" method exactly do ? when it executes the "updte" on record 1, based on what you said, it does not immediately insert and hold it until record 10 is done with its "update" and then it inserts records 1 to 10 at same time. is that right ?
Then again what does "update" do on record 1 ?



Yes, exactly. It will hold onto all ten statements then send all ten in one call to the database.

Mark
 
snakes are really good at eating slugs. And you wouldn't think it, but so are tiny ads:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic