Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Avoid Duplicate entries in MySQL table

 
Tarik Ansari
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HEllo,

Please tell me how to chk for Duplicate entry message in JDBC Update query.

Eg:if i have a mobile no in a table it shud not allow me to enter the same number,instead it shud give a message "Mob no already exists"

thanks
Tarik Ansari [edited out e-mail - Please use the forum not e-mail]
[ December 31, 2008: Message edited by: Tarik Ansari ]
[ December 31, 2008: Message edited by: Jeanne Boyarsky ]
 
Campbell Ritchie
Sheriff
Posts: 48424
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch

You could try searching for the mobile number in the database before inserting, but it is probably better to use the UNIQUE keyword in the SQL. You will get a straightforward SQLException with error state, error code, and message.
 
Bosun Bello
Ranch Hand
Posts: 1510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If possible add the UNIQUE keyword to the table's definition for that column.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic