Exception handling
Proper database management requires that you know whether the database server successfully processes your SQL statements as you intend. If a query fails and you do not know it, you might display meaningless data to the user. A more serious consequence might be that you update a customer account to show a payment of $100, and the update fails without your knowledge. The account is now incorrect.
To
handle such error situations, your program
must check that every SQL statement executes as you intend. These
topics describe the following exception-handling information:
- How to interpret the diagnostic information that the database server presents after it executes an SQL statement
- How to use the SQLSTATE variable and the GET DIAGNOSTICS statement to check for runtime errors and warnings that your program might generate
- How to use the SQLCODE variable and the SQL Communications Area (sqlca) to check for runtime errors and warnings that your program might generate
- How to choose an exception-handling strategy that consistently handles errors and warnings in your programs
- How to use the rgetlmsg() and rgetmsg() library functions to retrieve the message text that is associated with a given HCL OneDB™ error number
The end of these topics present an annotated example program that is called getdiag. The getdiag sample program demonstrates how to handle exceptions with the SQLSTATE variable and the GET DIAGNOSTICS statement.