-1

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?

Shayki Abramczyk
  • 36,824
  • 16
  • 89
  • 114

3 Answers3

1

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)

Mena
  • 3,019
  • 1
  • 25
  • 54
0

It seems like the check [Skip Tests] checkbox can be helpful.

You can find it through Settings---Build, Execution, Deployment---Build Tools---Maven---Runner(Intellij IDEA).

Radu Linu
  • 1,143
  • 13
  • 29
-2

This happens on an update statement which has nothing to do with the Primary Key I believe. Kinda messy situation. When you execute the same SQL statements on sql prompt, it gives perfect result and if you add a delay to the same program and run it again it might work too. Think its something to do with the JDBC mysql connection when you run a considerable load at a stretch.