IBM Books

Building Applications for UNIX** Environments


Building and Running a CLI Program

To build the sample program clisampl:

  1. Go to the window in which you set your environment variables. In order to do this, run db2profile. Refer to "Setting Your Environment" if you need more information.

  2. Build the sample program by entering:
    clibld
    

The result is an executable file clisampl. You can run the executable file to see how it works. The sample program accepts command line arguments for a database, user ID, and password so you can connect to any database to which you have access.

To run the sample program, enter:

clisampl database userid password

where

database
Is the name of a cataloged database.

userid
Is a user ID that has SYSADM authority.

password
Is a valid password.

If you need information about cataloging databases, or about SYSADM authority and passwords, refer to the Quick Beginnings book for your platform.

The clisampl program performs the following SQL operations using DB2 CLI function calls:

  1. Connects to a database.

  2. Creates a table.

  3. Inserts data into the table using a parameter marker.

  4. Selects the data.

  5. Drops the table.

  6. Disconnects from the database.

You should see the following output:

Connecting
Create table - CREATE TABLE CLISAMPL (COL1 VARCHAR(50))
Insert - INSERT INTO CLISAMPL VALUES (?)
Select - SELECT * FROM CLISAMPL
Number of columns - 1
Column name - COL1
Column type - 12
Column precision - 50
Column scale - 0
Column nullable - TRUE
Column value - Row 1
Column value - Row 2
Disconnecting
Exiting program


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]

[ DB2 List of Books | Search the DB2 Books ]