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

  • SEARCH
  • Home
  • 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 8629699
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:52:18+00:00 2026-06-12T08:52:18+00:00

I have multiple prepared statements. Do I need to execute ‘connection.commit’ for every statement

  • 0

I have multiple prepared statements. Do I need to execute ‘connection.commit’ for every statement or call only once after the last statement?

Connection connection = datasource.getConnect();
connection.setAutoCommit(false);
PreparedStatement pstmt1 = connection.prepareStatement(query1);
pstmt1.executeUpdate();
connection.commit();

PreparedStatement pstmt2 = connection.prepareStatement(query2);
pstmt2.executeUpdate();
connection.commit();

PreparedStatement pstmt3 = connection.prepareStatement(query3);
pstmt3.executeUpdate();
connection.commit();


Or

Connection connection = datasource.getConnect();
connection.setAutoCommit(false);
PreparedStatement pstmt1 = connection.prepareStatement(query1);
pstmt1.executeUpdate();

PreparedStatement pstmt2 = connection.prepareStatement(query2);
pstmt2.executeUpdate();

PreparedStatement pstmt3 = connection.prepareStatement(query3);
pstmt3.executeUpdate();

connection.commit();

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-12T08:52:19+00:00Added an answer on June 12, 2026 at 8:52 am

    If you set autocommit = false, then you can choose when you commit the transaction. Where that is best done, only you can judge as it depends upon atomicity, transaction isolation etc.

    That’s the whole point of exposing the autoCommit property to you, the “end-user”, so you have control over how changes relate to/dependent upon each other.

    What you can’t do (I’m pretty sure – it’s been a while since I programmed in JDBC directly) is issue 2 commit commands without any other command in between.

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

Sidebar

Related Questions

I have multiple ajax requests with javascript code as response, and I need to
I have a problem in which I need to be prepared to explore a
I have a web application using PHP and PDO with SQLSRV prepared statements to
Is there a way to select multiple values with prepared statements in (My-)SQL? I'm
I have been learning to use prepared and bound statements for my sql queries,
I need to store select statement results (multiple rows and Columns) in a variable
What exactly are the rules for setting up multiple prepared statements simultaneously (with a
I have multiple projects which are to be hosted together in a Tomcat container,
I have multiple UpdatePanels on a webpage, one inside UserControl (Purple ColorBox as show
I have multiple forms for lots of products on my page and want to

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.