How to get the cause of a SQLException from a SQLException object
I am using JDBC and running a request. Is there a way to get the reason for the failure of the returned SQLException object?
Specifically, I want to know if my query has violated a foreign key constraint (and which one) or a key constraint.
Will this result be vendor specific? Just in case, I'm using the postgresql-8.4-701.jdbc4.jar driver. If it depends on the provider, where can I find the codes?
EDIT: I want to do this dynamically - i.e.
if(violated foreign key constraint on attribute x) {
return 5;
} else if (violated primary key constraint) {
return 7;
} else {
return 0;
}
Or something like that.
EDIT: According to this post , there are no vendor specific error codes for PostgreSQL JDBC. Dunno if it's still relevant.
+3
source to share