I'm creating a simple form that stores entered data in an extremely simple Oracle database table via a Java Servlet using JDBC. That table is using the email address as a primary key. If a user submits a form multiple times with the same email address, the execute
function fails and throws a SQLException. The exception's string is the following:
java.sql.SQLException: ORA-00001: unique constraint (...removed...) violated
In this scenario, I would like to catch this exception and deal with it by telling the user that the form cannot be submitted multiple times with the same email address. What is the proper way to handle ORA-00001 separately and differently from any of the other SQLExceptions that can be thrown by execute
? A string compare could obviously work here, but that seems like a poor solution.
If you don't need to be DBMS independent use SQLException.getErrorCode()
It returns the vendor specific numeric error code. For ORA-0001 this would be 1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With