Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9044653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T11:02:28+00:00 2026-06-16T11:02:28+00:00

In our application, we have a few use cases where we need to update

  • 0

In our application, we have a few use cases where we need to update a lot of entries in a database table. We have a DataAccess object that we use for interacting with the database.

The code for updating looks like this.

String updateQuery = "UPDATE tbl SET column1=? WHERE column2=?";
for(i=0;;i++){
    Map<Integer, Object> params=new HashMap<Integer, Object>();
    params.put(1,"val"+i);
    params.put(2,"val"+i);
    DataAccess.addBatchParams(updateQuery,params);
}
DataAccess.executeBatch(updateQuery);

Inside DataAccess.addBatchParams(..)

public void addBatchParams(String query, Map<Integer,Object> params){
    ..  // preparedStatements contains all params passed till now.
    ..  
    if(preparedStatements.size() >= BATCH_SIZE){
        executeBatch(query);
        //flush preparedStatements as it has been written to db
    }
    ..  
    ..  
}

My concern is that, whenever a new developer uses this, there is no way for him to know that he has to call executeBatch() method at the end of every batch update for flushing out the last few entries lesser than BATCH_SIZE to the db. Is there any better way to do this? Is there any design pattern or something for doing a database batch update?

Any help is appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T11:02:29+00:00Added an answer on June 16, 2026 at 11:02 am

    Consolidate both methods together and make the addBatchParams and executeBatch methods private.

    public void executeBatch(String query, 
        List<? extends Map<Integer,Object>> paramsList) {
        for (Map<Integer,Object> params : paramsList) {
            addBatchParams(query, params);  
        }
        executeBatch(query);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In our application we have a little query that looks like this: var selectedAgents
We have two tables in our application that both have a ShowOrder column. We
Our application is a Java-GWT application that uses Guice-Persist and Guice-Servlet extensively. We have
We use MVC controllers that access System.File.IO in our application and they work fine
I have a few little scripts that I use for monitoring some aspects of
In our company, we have bought a web application that we are testing in
Our application is interfacing with a lot of web services these days. We have
in our application we have a Java applet running inside a .NET browser control.
In many places in our application we have code like this: using(RAPI rapi =
In our ColdFusion application we have stateless model objects. All the data I want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.