DB2 CLI includes various sample applications in the {DB2PATH}/samples/cli directory (where {DB2PATH} is the directory the DB2 SDK product was installed). The README file in the same directory lists each sample along with an explanation, and describes how to build the samples using the make facility (with the makefile that is also included).
DB2 CLI provides a way to ensure that your compiler environment is set up correctly without using the make facility. A sample application is included that is compiled and linked using a file composed of compile and link commands; a build script. The build script is a command file (.cmd) in OS/2, a batch file (.bat) in Windows, and a script file on UNIX platforms. Once you compile and link the sample application you can run it with command line arguments for the database, user id and password. This allows the application to connect to any database that you have access to.
The appropriate compiler must be installed and setup before continuing.
Copy the sample application and command file to a test directory to which you have write access, and execute the command file.
Execute the resulting executable file by entering:
clisampl database userid password
Where:
The example program performs the following SQL operations using DB2 CLI function calls:
Expected 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
The output of the Windows 3.1 program is written into a file named "clisampl.log" in the directory where the executable is invoked.