*
The moose likes Spring and the fly likes Is this really a batch update Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Is this really a batch update" Watch "Is this really a batch update" New topic
Author

Is this really a batch update

Raj Ohadi
Ranch Hand

Joined: Jun 30, 2006
Posts: 316
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 ?
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

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


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Raj Ohadi
Ranch Hand

Joined: Jun 30, 2006
Posts: 316
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
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

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
 
Consider Paul's rocket mass heater.
 
subject: Is this really a batch update
 
Similar Threads
Spring StoredProcedure + RowMapper issue
Retrieve Number of Rows Affected in Calling Stored Procedure
Spring :Approach to call Stored Procedures
spring jdbcTemplate connection
trouble passing array to stored procedure in spring HELP