You can review error
information that is returned in the SQLCODE and SQLSTATE fields of
the SQLCA structure. The SQLCA structure is updated after every executable
SQL statement and most database manager API calls.
Before you begin
If your application is compliant with the FIPS 127-2
standard, you can declare host variables named SQLSTATE and SQLCODE
instead of explicitly declaring the SQLCA structure in embedded SQL
applications.
- The PREP option LANGLEVEL SQL92E needs to be specified
About this task
In the following example, the application checks the SQLCODE field
of the SQLCA structure to determine whether the
update was successful.
Table 1. Embedding
SQL Statements in a Host LanguageLanguage |
Sample Source Code |
C and C++ |
EXEC SQL UPDATE staff SET job = 'Clerk' WHERE job = 'Mgr';
if ( SQLCODE < 0 )
printf( "Update Error: SQLCODE =
|
COBOL |
EXEC SQL UPDATE staff SET job = 'Clerk' WHERE job = 'Mgr' END_EXEC.
IF SQLCODE LESS THAN 0
DISPLAY 'UPDATE ERROR: SQLCODE = ', SQLCODE.
|
FORTRAN |
EXEC SQL UPDATE staff SET job = 'Clerk' WHERE job = 'Mgr'
if ( sqlcode .lt. 0 ) THEN
write(*,*) 'Update error: sqlcode = ', sqlcode
|