In my database I've crated a unique constraint that controls the uniqueness of IDTYPE and IDNO pairs. So there cannot be a second row that has IDTYPE of 1 and IDNO of 11232. Obviously if I violate this my application will crash with oracle unique constraint error. How can I catch this and any other error because I do not want to run a query to check if there's any other row having the same value of IDNO and IDTYPE. If I can catch this error I can show my own description instead of Oracle's one that only we programmers can understand.
Asked
Active
Viewed 487 times
0
-
1Here's a [link](http://stackoverflow.com/questions/10091199/using-unique-key-in-sql-with-or-without-try-catch-as-a-valid-way-to-verify-integ) for SQL Server approach (both the question and answers tell you how to deal with it) but it should be the same for Oracle. – MadBoy Apr 13 '12 at 11:30
-
Yeah, that'll do the job I guess – Mikayil Abdullayev Apr 13 '12 at 12:05
1 Answers
1
So, if I haven't misunderstood, you're looking for a try-catch statement, just like this
try { //code to access DB }
catch (Exception e) { //do some stuff }

Sergio Rosas
- 545
- 12
- 27