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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:34:18+00:00 2026-05-23T21:34:18+00:00

Hi I am developing a site with JSP/Servlets running on Tomcat for the front-end

  • 0

Hi I am developing a site with JSP/Servlets running on Tomcat for the front-end and with a MySql db for the backend which is accessed through JDBC.

Many users of the site can access and write to the database at the same time ,my question is :
Do i need to explicitly take locks before each write/read access to the db in my code?
OR Does Tomcat handle this for me?

Also do you have any suggestions on how best to implement this ? I have written a significant amount of JDBC code already without taking the locks :/

  • 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-05-23T21:34:18+00:00Added an answer on May 23, 2026 at 9:34 pm

    I think you are thinking about transactions when you say “locks”. At the lowest level, your database server already ensure that parallel read writes won’t corrupt your tables.

    But if you want to ensure consistency across tables, you need to employ transactions. Simply put, what transactions provide you is an all-or-nothing guarantee. That is, if you want to insert a Order in one table and related OrderItems in another table, what you need is an assurance that if insertion of OrderItems fails (in step 2), the changes made to Order tables (step 1) will also get rolled back. This way you’ll never end up in a situation where an row in Order table have no associated rows in Order items.

    This, off-course, is a very simplified representation of what a transaction is. You should read more about it if you are serious about database programming.

    In java, you usually do transactions by roughly with following steps:

    1. Set autocommit to false on your jdbc connection
    2. Do several insert and/or updates using the same connection
    3. Call conn.commit() when all the insert/updates that goes together are done
    4. If there is a problem somewhere during step 2, call conn.rollback()
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing a simple servlet/JSP, data-driven web site on Google App Engine. I've started
I'm developing a site which has a flash background playing a small video loop
While developing a site which I can't link to directly, I've found a following
I am developing site using codeigniter.I have a form which contains add button and
I'm developing site which provides allow to display external sites into iframe with extra
often many site developing sticky slide menu. the menu slide out from bottom right
I'm developing a site that uses OpenID for authentication, which is working fine however...
I am currently developing a site which requires a print option on the page.
I am developing site with WordPress and I'm newbie for WordPress. WP adds <p>
I'm developing a site in Visual Web Dev Express, and when I run/debug, I'd

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.