This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JDBC and the fly likes Avoid Duplicate entries in MySQL table Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Avoid Duplicate entries in MySQL table" Watch "Avoid Duplicate entries in MySQL table" New topic
Author

Avoid Duplicate entries in MySQL table

Tarik Ansari
Ranch Hand

Joined: Dec 31, 2008
Posts: 50
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

Joined: Oct 13, 2005
Posts: 38057
    
  22
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

Joined: Nov 06, 2000
Posts: 1510
If possible add the UNIQUE keyword to the table's definition for that column.


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
 
wood burning stoves
 
subject: Avoid Duplicate entries in MySQL table
 
Similar Threads
Form submit in Href
JQuery XML- Permission denied
createEntityManagerFactory null
JLabel icons
JMS not bound? What is this?