hi all I have a database with unique constraint. How can I differentiate the "unique constraint exception" (and manage this one in the application) and an another exception that i don't want to manage (just catch and no information to final user). Do I have to check the constraint with a request before and throw my own exception or is it possible to recognize the exception.??? thx
Gayathri Prasad
Ranch Hand
Joined: Jun 25, 2003
Posts: 116
posted
0
Hi, When ever there is unique contraint violation the Database throws some number exception. We need to identify the exceptions depending on the number the DBengine returns. I think we dont have any exception classes for this and hence we need to code in our custom exception class. Cheers, Gaya3
Tim Morrow
Greenhorn
Joined: Sep 17, 2003
Posts: 11
posted
0
As mentioned previously there is a vendor-specific error code available from SQLException. You can check that value and handle it appropriately. You'd need to look up the particular error for your database and determine its error code. Take a look at the Javadoc for java.sql.SQLException. Also, the original error may be nested a few exceptions deep, so you may also have to traverse the nested exceptions inside SQLException. For example, assuming your "Unique constraint violated" error code is error code "1" for your database (believe this is correct for Oracle) you might write: