Building CLI applications on Windows

Db2® provides batch files for compiling and linking CLI programs. These are located in the sqllib\samples\cli directory, along with sample programs that can be built with these files.

About this task

The batch file bldapp.bat contains the commands to build a CLI program. It takes up to four parameters, represented inside the batch file by the variables %1, %2, %3, and %4.

The parameter, %1, specifies the name of your source file. This is the only required parameter, and the only one needed for CLI programs that do not contain embedded SQL. Building embedded SQL programs requires a connection to the database so three optional parameters are also provided: the second parameter, %2, specifies the name of the database to which you want to connect; the third parameter, %3, specifies the user ID for the database, and %4 specifies the password.

If the program contains embedded SQL, indicated by the .sqc or .sqx extension, then the embprep.bat batch file is called to precompile the program, producing a program file with either a .c or a .cxx extension.

The following examples show you how to build and run CLI applications.

To build the sample program tbinfo from the source file tbinfo.c, enter:
 
   bldapp tbinfo
The result is an executable file tbinfo. You can run the executable file by entering the executable name:
   tbinfo
Building and running embedded SQL applications

There are three ways to build the embedded SQL application, dbusemx, from the source file dbusemx.sqc:

Procedure

  1. If connecting to the sample database on the same instance, enter:
       bldapp dbusemx
  2. If connecting to another database on the same instance, also enter the database name:
       bldapp dbusemx database
  3. If connecting to a database on another instance, also enter the user ID and password of the database instance:
       bldapp dbusemx database userid password
    The result is an executable file, dbusemx.
    There are three ways to run this embedded SQL application:
    1. If accessing the sample database on the same instance, simply enter the executable name:
         dbusemx
    2. If accessing another database on the same instance, enter the executable name and the database name:
         dbusemx database
    3. If accessing a database on another instance, enter the executable name, database name, and user ID and password of the database instance:
         dbusemx database userid password