0

I parse a .lst file to get data, then I use hibernate in order to add these data in a mysql database.

My file is always updated with new data but it KEEPS existing ones.

The question is how can I avoid duplicates data in my database when I parse the file a scond time.

Thanks

Marouane
  • 21
  • 8
  • By adding a unique index in my database I risk to have an exception in my code, because I try to add elements that won't be accepted in my database. I'll test it anyway and I'll tell you if it works. Thanks for your reply. – Marouane Oct 28 '15 at 10:15

1 Answers1

0

INSERT INTO table_name ('your fields') VALUES ('New values') ON DUPLICATE KEY UPDATE field1=' value',field2='value',.....;

Table Structure: make this 2 fields (name and city )Uniqe ex:

INSERT INTO tbl_stud(name,city)values('Divyesh','Ahmedabad') ON DUPLICATE KEY UPDATE name='Divyesh',city='Ahmedabad';

Divyesh
  • 389
  • 2
  • 12