How to identify the sub type of inetgrity constraint violation programmatically & vendor-neutrally?
posted 7 years ago
Can anyone let me know if there is any way to use the SQLIntegrityConstraintViolationException (Java 5 onwards I think) to find out if "unique constraint" (or) "referential integrity constraint i.e. parent key not found" has happened? I have done this in Oracle specific manner and it works but I wish to know if there is a vendor neutral way. I am not using Spring and cannot add support for it in my current application otherwise I could try something like what is mentioned in this URL SpringSource.
I used the SQL error code returned by Oracle (1 for unique constraint, 2291 for referential integrity) because though vendor neutral, the SQL state eems to return 23000 for both types.
Expecting some help from anyone who has succeeded doing it (as that would be cleaner code that writing vendor-specific),