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 8594231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:09:09+00:00 2026-06-12T00:09:09+00:00

First, I will try to describe what I am willing to do and then,

  • 0

First, I will try to describe what I am willing to do and then, I will ask my questions.
I need to do the following:

  • List all rows corresponding to some conditions
  • Do some tests (e.g: check if it wasn’t already inserted), if test passes then insert row into another database
  • Delete row (whether it passed tests or not)

The following is my implementation

List<MyObject> toAdd = new ArrayList<MyObject>();
for(MyObject obj:list){
    if(!notYetInserted(obj){
        toAdd.add(obj);
    }
}
myObjectDAO.insertList(toAdd);
myObjectDAO.deleteList(list);

The service method is marked transactional.

In my DAO methods for deleteList and insertList are pretty similar so I will just put here method for insert.

public void insertList(final List<MyObject> list){
String sql = "INSERT INTO table_test " +
    "(col_id, col2, col3,col4) VALUES (?, ?, ?,?)";

List<Object[]> paramList = new ArrayList<Object[]>();

for (MyObject myObject : list) {
    paramList.add(new Object[] {myObject.getColId(), 
        myObject.getCol2(), myObject .getCol3(), myObject.getCol4()}
    );
}
simpleJdbcTemplate.batchUpdate(sql, paramList);        

}

I am not sure about the best way to perform such operations, I read here that calling for update inside a loop may slow down the system (especially in my case, I will have about 100K insert/delete at a time). I wonder if these additional loops inside DAO won’t slow down my system even more and what would happen if problem happened repeatedly while processing that batch (I thought also about moving test from service to DAO to have only one loop and an additional test, I don’t really know if it’s a good idea). So, I would like your advices. Thanks a lot.

PS: if you need more details feel free to ask!

  • 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-12T00:09:10+00:00Added an answer on June 12, 2026 at 12:09 am

    This is not necessarily a bad approach, but you are right, it might be really slow. If I were to do a process like this that inserted or deleted this many rows I would probably do it all in a stored procedure. My code would just execute the proc and the proc would handle the list and the enumeration through it (as well as the inserts and deletes).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my first time on stackoverflow asking questions so I will try my
First of all, execuse the longer question, but I will try to put it
I will first describe the problem and then what I currently look at, in
First I will try to explain what I want to do. The app loads
I will try to be specific if I can - please be patient, first
I will first illustrate my issue with some code: class ExampleClass { private Vector2
I want to create a captcha in my website. I will try to describe
First I will describe what I am trying to accomplish here. I have a
First time posting, I will try to adhere to best practices. I'm trying to
First of all, I know the standard answer will be that exceptions are never

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.