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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T13:27:02+00:00 2026-06-07T13:27:02+00:00

Currently our application uses Spring, SimpleJdbcTemplate & MySQL. DataSource used is org.apache.commons.dbcp.BasicDataSource with url

  • 0

Currently our application uses Spring, SimpleJdbcTemplate & MySQL.

DataSource used is org.apache.commons.dbcp.BasicDataSource with url properties “rewriteBatchedStatements=true”.

During the batch insert with SimpleJdbcTemplate.batchUpdate(List<Object[]>), there will be duplicate records(based on the primary key of the table we are inesrting) in the input batch.

Under the duplicate record scenario is it possible to

1) Insert all the non-duplicate records and get the response about the number of successful inserts?

OR

2) Completely rollback the batchInsert, no record should be inserted?

We are able to partially achieve the first requirement using the “INSERT IGNORE” of mysql. But the SimpleJdbcTemplate.batchUpdate() returns every record as updated.(Not able to capture only the inserted record count ignoring the duplicates)

And to achieve the second requirement we have to turn off the “rewriteBatchedStatements”. But this parameter has been fine tuned after performance test. So we can’t set this to “false”.

Is the possible to achieve one of two above cases, within the constraints of the components we are using as mentioned in the first line?

I am new to spring and jdbc world, so a detailed explanation will help us better.
Thanks

  • 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-07T13:27:04+00:00Added an answer on June 7, 2026 at 1:27 pm

    1) Insert all the non-duplicate records and get the response about the number of successful inserts?

    => Well you can, insert all non.duplicate records, and get the response. batchUpdate() returns int[] i.e. array of integers which represents the numbers of rows affected by each update in the batch (inserted/updated).

    2) Completely rollback the batchInsert no record should be inserted?

    => As batchInsert will be within single transaction, either all records will be inserted or no record is inserted. If transaction gets committed all records will be inserted. If any exception occurs, transaction will be rolled back automatically if you are using spring transaction management (either using @Transactional annotation or spring aop based tx advice). Here make sure, you set BasicDataSource.defaultAutoCommit = false.

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

Sidebar

Related Questions

Our application currently stores bunch of configuraton & application specific data to files on
Currently our Java application uses the values held within a tab delimited *.cfg file.
Currently, our application uses a javax.mail to send email, using javax.mail.MailMessage. We set the
Currently our application uses GWT-RPC for most client-server communication. Where this breaks down is
We are currently migrating our VB6 application to Net. The VB6 code uses some
Our application is currently made up of two big entities: C# ASPX files, and
We are currently calling web services on our application server through our web server
I'm currently going through the process of running FxCop through our application that has
An application our company is working on currently displays many rectangle shapes with gradients
I am currently introducing a mobile friendly version of our web-application. In a first

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.