This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I've search thouroughly for the solution to this problem but with no success. All related solutions apply to insertint new records. I have found non for updating the database table.
I have a database with containing a primary key (with auto increment attribute). I then present the databse content in a jtable interface.
Now, I will want the database to be updated from the jtable interface.
This is the function I try to use to accomplish that:
However, I get the following error when update button is hit:
com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry '4' for key 'PRIMARY'
The strange thing is that on a few ocasions the update works without showing this error. How can I resolve this issue. Your advice would be much appreciated.
Could there be any possibility that you are trying to update a primary key value with one that already exists in the table?
Joined: Dec 17, 2011
Gamini Sirisena wrote:Could there be any possibility that you are trying to update a primary key value with one that already exists in the table?
I think this is exactly what is happening. I simply select and show all columns of the database (including the primary key) in a jtable and then use a button to update the database when changes are made to the table.
Actually, the primary key is not changed but its value is included in the data being updated (saved to the database).
Is there a better way to do this (i.e. using jtable to modify my database table)?