• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to recognize integrity constraint from exception

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

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

MysqlIntegrityConstraintViolationException

exception

Can anybody suggest the best way to do it ?

 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Tanvi Narula
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Paul for the quick reply

I guess I will have to parse the exception ...

 
Did Steve tell you that? Fuh - Steve. Just look at this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic