0
votes

When I update or insert in jbdc4 I got this error:

com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry '0006-0208-254-3491-254254-01774' for key 'PRIMARY' at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at com.mysql.jdbc.Util.handleNewInstance(Util.java:409) at com.mysql.jdbc.Util.getInstance(Util.java:384)

Any solution?

1
Solution is to not use the same primary key value twice. - Robby Cornelissen
can show for the example, please.?? thank you - Zamil Nugraha
What example? Just don't insert the same primary key twice. - Robby Cornelissen
that's just one same primary bro - Zamil Nugraha
if you try add same primary key, you will end up wiht this error, Primary key is Unique entry, consider update instead of insert stackoverflow.com/questions/36442307/… - Raso

1 Answers

0
votes

This error message tells you that you are trying to insert an entry in the database that has a primary key value equal to one of a previously inserted entry. This is the function of a primary key, is to be able to uniquely identify an entry, and prevent duplicate values of the field that is selected to be a primary key.

Example: If you have a table with the following columns("id","age"). If you choose "id" to be the primary key, then you cannot insert the following entries:

*insert (1,20)

*insert (1,25) -->Here it will give you the above mentioned error in your question.

Instead, you can insert the following:

*insert (1,20)

*insert (2,25) or insert (2,20)