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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:55:25+00:00 2026-05-25T17:55:25+00:00

When we program with database (for example in Java and MySql), should we check

  • 0

When we program with database (for example in Java and MySql), should we check for duplicate entry before inserting, or should we just insert and catch the duplicate exception to raise alert to users ?

In my opinion, if we do the check, and if there is no duplicate entry, we insert the entry, and the database engine itself checks for duplicate primary key again. It sounds a waste of time.

How do you think?

  • 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-25T17:55:26+00:00Added an answer on May 25, 2026 at 5:55 pm

    For you to check client side(in your program) if there is a duplicate key, it would require querying the database. Since the insert query will return an error if there is already a record existing with the same PK, it is not necessary to perform this check before the insert statement is sent.
    You can insert, catch the exception/error code (i’m not sure if it will give an exception in java, or return an error code) and then alert the user.

    EDIT –
    If there are many users using the same database, the main issue if you check and then insert will be that someone else can insert the same key after you checked but before you insert. IF you would like to do it this way, you would need to use transactions – the check and insert must both happen in the same transaction. You can read up on MySQL transactions here.

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

Sidebar

Related Questions

I write Java program using JDBC (mysql database). When I violate mysql integrity (f.e.
I have a java program that connects to a MySql database and it's working
for example when i retrieve from database the word program's instead of program's what
How to use sql compact database from a non .NET program? For example I
I am writing a full database extract program in java. Database is Oracle, and
Is there a simple database program to let me collect, sort, tag, and reguritate
I'm working on a database program and I noticed that when I'm doing queries
I have a classic client/server (fat client and database) program written in Delphi 2006.
If my program was to hit the database with multiple updates would it be
I have a program that continually polls the database for change in value of

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.