Posted on 2011-05-06
Last Modified: 2012-05-11
I was reading folowing lines and I did not understand clearly.
return jdbcTemplate.batchUpdate(sql, setter);
To Execute batch
 JDBC driver supports batching, the updates will be batched, creating
more efficient database access. If not, Spring will simulate batching, but the statements
will be executed individually.

Why we used jdbcTemplate. what is difference between batch execute and executing a statement.
Any ideas, resources,sample code,links, highly appreciated. thanks in advance.
Question by:gudii9
    LVL 47

    Accepted Solution


    Well, some database servers operate differently when
    you ask them separately to update 20 records of the same type
    (say 20  rows in one table) one by one, or if you tell them upfront - this
    is the way I want to modfy my records - these are 20 values to find these
    records, these are 20 values to update these particular field of
    these records , and now-  go update all 20 of them. In some smart databases, when you say
    upfront - the database will first design the best way to update
    and then use this way 20 times just replacing paramters, whereas if you communicate it
     to database  one by one - it
    will 20 times spend time designing the best way to update it.
    So if database makes such distinction in operations between
    single updates and bulk updates it may save some time for bulk updates.

    This  statement emphasizes the point that although jdbcTemplate in its
    template (which we mentioned in another question) has this idea that if we want to do 20 updates
    we first should communicate to database our intention and
    the arrays of data, rather than feed them one by one.
    So while jdbcTemplate knows that it should work in this mode(template),
    the actual implementation - in fact the driver for the
    particulr database - may either take advantage of such option
    or not. So jdbcTemplate will know that it will
    want to request such option, but if it is not avialbale, driver
    will still do the update one by one. That again
    illustrates difference between interface and implementation - independent
    of databses and driver 20 records will be updated, howvere
    actuual mechnism, which will be used, will depend on the
    implementation in the driver.

    LVL 92

    Assisted Solution

    Batching improves performance by allowing the updates to be 'precompiled' by the driver allowing just the parameters to be sent for each update.

    Important to understand that batching still sends multiple updates, it just minimises the amount of processing required for each update. And you still need to add all the updates one at a time.

    Also the queries sent to the database are exactly the same whether you are using a batch update or not, it will still recieve a single update for each one you send. ie. batching has nothing to do with the database server.

    To achieve this the statement for all the updates needs to be the same, only the parameters can differ

    you can read about jdbc batch updates here

    What JdbcTemplate offers is its own inbuilt support for batching which will get used if batching is not supported. It s better than just doing updates, but no as fast as 'native' batching.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Suggested Solutions

    Title # Comments Views Activity
    Using java code in .Net/c#: namespace issue 3 38
    Problem to setup 18 66
    count11 challenge 6 32
    wordlen challenge 3 27
    This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
    Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
    Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
    This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now