Using SQLSTATE in Applications
You can use a built-in variable, called SQLSTATE, which you do not need to declare in your program. SQLSTATE contains the status code, essential for error handling, which is generated every time your program executes an SQL statement. SQLSTATE is created automatically. You can examine the SQLSTATE variable to determine whether an SQL statement was successful. If the SQLSTATE variable indicates that the statement failed, you can execute a GET DIAGNOSTICS statement to obtain additional error information.
For an example of how to use an SQLSTATE variable in a program, see Using GET DIAGNOSTICS for Error Checking.