Application Building Guide

Creating, Cataloging, and Binding the Sample Database

To use the sample programs shipped with DB2, you need to create the sample database on a server workstation. Refer to the SQL Reference for a listing of the contents of the sample database.

If you will be using a remote client to access the sample database on the server, you need to catalog the sample database on the client workstation.

Also, if you will be using a remote client to access the sample database on a server that is running a different version of DB2, or running on a different operating system, you need to bind the database utilities, including the DB2 CLI, to the sample database.

Creating

To create the sample database, you must have SYSADM authority. If you need more information about SYSADM authority, refer to the Quick Beginnings book for your operating system.

To create the database, do the following on the server:

  1. Ensure that the location of db2sampl (the program that creates the sample database) is in your path. The db2profile or db2cshrc file will put db2sampl in your path, so it will remain there unless you change it.
  2. Ensure that the DB2INSTANCE environment variable is set to the name of the instance where you want to create the sample database. If it is not set, you can set it with the following commands:

    where instance_name is the name of the database instance.

  3. Create the sample database by entering db2sampl followed by where you want to create the sample database. On UNIX platforms, this is a path, and would be entered as:
       db2sampl path
    

    On OS/2 and Windows, this is a drive, and would be entered as:

       db2sampl drive
    

    If you do not specify the path or drive, the installation program installs the sample tables in the default path or drive specified by the DFTDBPATH parameter in the database manager configuration file. If you need information about the configuration file, refer to the Administration Guide.

    The authentication type for the database is the same as the instance in which it is created. If you need more information about specifying authentication when creating a database instance, refer to the Quick Beginnings book.

Creating on Host or AS/400 Servers

If you want to run the sample programs against a Host server such as DB2 for OS/390, or an AS/400 server, you need to create a database that contains the sample tables described in the SQL Reference. You may want to refer to the sample program, expsamp (C: expsamp.sqc ; COBOL: expsamp.sqb ), which uses the STAFF and ORG tables to demonstrate how APIs are used to import and export tables and table data to and from a DB2 Connect database.

To create the database:

  1. Create the sample database in a DB2 server instance using db2sampl.
  2. Connect to the sample database.
  3. Export the sample tables to a file.
  4. Connect to the DB2 Connect database.
  5. Create the sample tables.
  6. Import the sample tables.

If you need information about exporting and importing files, refer to the Data Movement Utilities Guide and Reference. If you need information about connecting to a database and creating tables, refer to the SQL Reference.

Cataloging

To access the sample database on the server from a remote client, you need to catalog the sample database on the client workstation.

You do not need to catalog the sample database on the server workstation because it was cataloged when you created it.

Cataloging updates the database directory on the client workstation with the name of the database that the client application wants to access. When processing client requests, the database manager uses the cataloged name to find and connect to the database.

The Quick Beginnings book provides general information on cataloging databases. This section provides specific instructions on cataloging the sample database.

To catalog the sample database from the remote client workstation, enter:

   db2 catalog database sample as sample at node nodename

where nodename is the name of the server node.

The Quick Beginnings book explains how to catalog nodes as part of setting up communication protocols. You must also catalog the remote node before you can connect to the database.


[ Top of Page | Previous Page | Next Page ]