• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Avoid Duplicate entries in MySQL table

 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1514
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If possible add the UNIQUE keyword to the table's definition for that column.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic