This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
This topic was discussed long... back, where it was mentioned there is no way to recognize which integrity constraint occured when you get "MysqlIntegrityConstraintViolationException" in your code.
I am raising it again in the hope that some answer might be there now
I am using mysql with java and I have to generate custom messages when some DB exception occurs. While inserting or updating data , I need to generate separate message for duplicate key violation and foreign key violation on receiving
JDBC just reports what the database server tells it when something goes wrong. You will need to interpret the error code associated with the exception if there is one or worst case parse the message.
However, if this is because of an insert or update I would not expect the user to ever hit an integrity constraint violation exception. Should your busness and dao logic not be creating valid data for them?