aspose file tools*
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 Java 8 in Action this week in the Java 8 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: 36599
    
  16
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: 1506
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
 
Similar Threads
createEntityManagerFactory null
JMS not bound? What is this?
JLabel icons
JQuery XML- Permission denied
Form submit in Href