• 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

Committing in intervals

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I would like to write a counter, such that I can do a database commit per every 10,000 row. how do I go about doing that using java and jdbc?
Thanks.
Luong
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
setAutoCommit false
If you are firing queries one row at a time
put a counter initialised to zero in the loop and increment it by one
When the counter reaches 10000, fire commit() and set the counter to zero
Continue till all records are inserted and fire commit in the finally block
 
Luong Phung
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Now what if I am not firing it off one row at a time, how do I go about doing it 10,000 rows at a time?
Much appreciated.
Luong
 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If your doing mass updates/inserts it is similar. For an update statement, you'll have to get the modified row count and add it a counter. Then you'll have to commit if the counter is 10,000 or greater. You won't be able to hit it exactly at 10,000 anymore. For the mass insert it must have a select statement part. Copy off the select statement part and modify it to a count(*), run it to get the row count and add it to the counter.
If this is not good enough, then you'll have to take extra effort to control how many rows are updated/inserted at a time. This may prove hard to do and the solution may be depenent on the specific driver or database you are using.
 
There's a way to do it better - find it. -Edison. A better tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic