DB2 10.5 for Linux, UNIX, and Windows

SQLSTATES for CLI

SQLSTATES are alphanumeric strings of five characters (bytes) with a format of ccsss, where cc indicates class and sss indicates subclass.
Any SQLSTATE that has a class of:
Note: Versions of CLI before Version 5 returned SQLSTATEs with a class of 'S1' rather than 'HY'. To force the CLI driver to return 'S1' SQLSTATEs, the application must set the environment attribute SQL_ATTR_ODBC_VERSION to the value SQL_OV_ODBC2.

CLI SQLSTATEs include both additional IBM defined SQLSTATEs that are returned by the database server, and CLI defined SQLSTATEs for conditions that are not defined in the ODBC version 3 and ISO SQL/CLI specifications. This allows for the maximum amount of diagnostic information to be returned. When running applications in an ODBC environment, it is also possible to receive ODBC defined SQLSTATEs.

Follow these guidelines for using SQLSTATEs within your application:
The code segment from utilcli.c shows how diagnostic information, such as SQLSTATEs, can be retrieved and displayed:
void HandleDiagnosticsPrint(SQLSMALLINT htype, /* handle type identifier */
                            SQLHANDLE hndl /* handle */ )
{
  SQLCHAR message[SQL_MAX_MESSAGE_LENGTH + 1];
  SQLCHAR sqlstate[SQL_SQLSTATE_SIZE + 1];
  SQLINTEGER sqlcode;
  SQLSMALLINT length, i;

  i = 1;

  /* get multiple field settings of diagnostic record */
  while (SQLGetDiagRec(htype,
                       hndl,
                       i,
                       sqlstate,
                       &sqlcode,
                       message,
                       SQL_MAX_MESSAGE_LENGTH + 1,
                       &length) == SQL_SUCCESS)
  {
    printf("\n  SQLSTATE          = 
    printf("  Native Error Code = 
    printf("
    i++;
  }

  printf("-------------------------\n");
}

You can use the CLI/ODBC trace facility to gain a better understanding of how your application calls DB2®, including any errors that might occur.