Creating the databases

To run the Error Handler sample, you must create two databases, each containing one table. The following script creates the databases that you need to run the Error Handler sample:

CREATE DB ERRORDB
CONNECT TO ERRORDB
BIND 'install_dir\bnd\@db2cli.lst' blocking all grant public
CONNECT RESET
CONNECT TO ERRORDB
DROP TABLE ERRORS
CREATE TABLE ERRORS (MSGID BLOB(48), TEXT CHAR(250), ERRORNUM INTEGER, ERRORDATE TIMESTAMP, FLOWNAME CHAR(32), NODENAME CHAR(32), MSGDATA BLOB(3200))
CONNECT RESET
CREATE DB STAFFDB
CONNECT TO STAFFDB
BIND 'install_dir\bnd\@db2cli.lst' blocking all grant public
CONNECT RESET
CONNECT TO STAFFDB
DROP TABLE STAFF
CREATE TABLE STAFF (STAFFNUM CHAR(10), LASTCHANGE TIMESTAMP, FIRSTNAME CHAR(30), LASTNAME CHAR(30))
CONNECT RESET
TERMINATE

The script performs the following tasks:

The instructions assume that you are using DB2 Universal Database. When you create and access the STAFFDB and ERRORDB tables, be aware of the following issues:

To create the databases:

  1. Copy and paste the script into a text editor.
  2. Replace both occurrances of install_dir with the installation path to the DB2 installation directory.
  3. Linux only: replace all the backslashes (\) with forward slashes (/).
  4. Save the file. You can choose any name for the file but the following instructions assume that you have called the file errorhandlerdb2.sql.
  5. In a DB2 Command Window, enter the following command to ensure that DB2 is started:

    db2start

  6. In a DB2 Command Window, move to the directory that contains errorhandlerdb2.sql, and enter the following command:

    db2 -vf errorhandlerdb2.sql

    Wait for the script to finish running. If you are running the script for the first time, the following message is displayed, where DB2ADMIN is your user name and TBNAME is the name of the table:

    DB21034E The command was processed as an SQL statement because it was not a
    valid Command Line Processor command. During SQL processing it returned:
    SQL0204N "DB2ADMIN.TBNAME" is an undefined name. SQLSTATE=42704

    Ignore these messages. The messages are displayed because the script attempts to drop any existing tables with the same name as the tables you are now creating, but if you have not run the script before, the program cannot find any such tables.

  7. Linux only: Set up the ODBC drivers:
    1. Open the /var/mqsi/odbc/.odbc.ini file in a text editor.
    2. In the .odbc.ini file, Locate the line that says: [ODBC Data Source] then insert the following lines below it:
      ERRORDB= IBM DB2 ODBC Database
      STAFFDB= IBM DB2 ODBC Database
    3. Add the following stanzas to the .odbc.ini file:
      [ERRORDB]
      Driver=/opt/IBM/db2/V8.1/lib/libdb2.so
      Description=ERRORDB DB2 ODBC Database
      Database=ERRORDB
      
      [STAFFDB]
      Driver=/opt/IBM/db2/V8.1/lib/libdb2.so
      Description=STAFFDB DB2 ODBC Database
      Database=STAFFDB

    The ODBC drivers are now configured correctly.

  8. Start the DB2 Control Center to check that the user database and tables have been created.

Back to Building the Error Handler sample

Back to sample home