This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have Dawn & David Griffiths on-line!
See this thread for details.
The moose likes JDBC and Relational Databases 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 Head First Android this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
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: 43359
    
  32
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Avoid Duplicate entries in MySQL table
 
jQuery in Action, 3rd edition