What is the proper way to catch and handle SARLO00001 SQLException using JDBC?

I am creating a simple form that stores input data in an extremely simple Oracle database table through Java Servlet using JDBC. This table uses the email address as the primary key. If the user submits the form several times with the same email address, the execute function fails and throws a SQLException. The exception line is as follows:

 java.sql.SQLException: ORA-00001: unique constraint (...removed...) violated 

In this scenario, I would like to catch this exception and deal with it, telling the user that the form cannot be submitted several times with the same email address. What is the correct way to handle ORA-00001 separately and differently from any other SQLExceptions that execute can choose? Obviously, string comparisons may work here, but this seems like a bad solution.

+7
source share
1 answer

If you do not need independent use of the DBMS SQLException.getErrorCode()

It returns the provider numerical error code. For ORA-0001 it will be 1

+13
source

All Articles