Setting up DB2
These instructions assume that you are using DB2 Universal Database and guide you through the
following tasks:
- Creating a database called STAFFDB for use by the Error Handler sample
- Binding the DB2 CLI packages
- Creating the tables STAFF for use by the Error Handler sample
- Creating the ODBC definition for the database
Note. When you create and access the database tables, be aware of the following issues:
- When you run the script that creates the tables, the user identifier from which you run the script
determines the database schema name. For example, if your user identifier is USERID, the fully qualified
name of the ERRORS table name is USERID.ERRORS.
- When you set a node to access a table, if the broker is not using the same user identifier to access
the database as you used when you created the database and tables, include the schema name in the node.
For example, Database.USERID.ERRORS.
Complete the following steps:
-
Open a new document in a text editor, copy and paste the following script,
which creates the STAFFDB database and runs the BIND utility,
into the document,
name the file errorhandler1.sql and save the file.
On Windows:
You must replace install_dir with the path to your DB2 product installation directory, such as
C:\PROGRA~1\IBM\SQLLIB. Obtain this location by using the
db2level command:
CREATE DB STAFFDB
CONNECT TO STAFFDB
BIND 'install_dir\bnd\@db2cli.lst' blocking all grant public
TERMINATE
On Linux:
You must replace install_dir with the path to your DB2 product installation directory. Obtain this location
by using the db2level command:
CREATE DB STAFFDB
CONNECT TO STAFFDB
BIND install_dir/bnd/@db2cli.lst grant public CLIPKG 5
TERMINATE
- In a DB2 command window, enter the following command to ensure that DB2 is started:
db2start
- In a DB2 command window, move to the folder that contains
errorhandler1.sql and enter the following command:
db2 -vf errorhandler1.sql
-
Open a new document in a text editor, copy and paste the following script,
which creates the STAFF tables,
into the document, name the file errorhandler2.sql and save the file.
CONNECT TO STAFFDB
DROP TABLE STAFF
CREATE TABLE STAFF (STAFFNUM CHAR(10), LASTCHANGE TIMESTAMP, FIRSTNAME CHAR(30), LASTNAME CHAR(30))
TERMINATE
- In a DB2 command window, move to the folder that contains
errorhandler2.sql and enter the following command:
db2 -vf errorhandler2.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 this message.
The message is displayed because the script attempts to remove any existing tables called
STAFF before it creates the new tables, but if you have not run the script before, the script
cannot find the existing tables.
- Create an ODBC definition for the STAFFDB database with STAFFDB as the data source name (DSN).
For instructions, see Enabling ODBC connections
to the databases in the WebSphere Message Broker documentation.
Back to Setting up the database