Building applications in C or C++ using the sample build script (UNIX)

You are provided with build scripts for compiling and linking embedded SQL and Db2® administrative API programs in C or C++. The scripts are in the sqllib/samples/c directory for C applications and the sqllib/samples/cpp directory for C++ applications. The directories include sample programs that you can build with these files.

About this task

The build file, bldapp, contains the commands to build a Db2 application program.

The first parameter, $1, specifies the name of your source file. This is the only required parameter, and the only one needed for Db2 administrative API 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.

For an embedded SQL program, bldapp passes the parameters to the precompile and bind script, embprep. If no database name is supplied, the default sample database is used. The user ID and password parameters are only needed if the instance where the program is built is different from the instance where the database is located.

The following examples show you how to build and run Db2 administrative API and embedded SQL applications.

Building and running Db2 administrative API applications
To build the Db2 administrative API sample program, cli_info, from the source file cli_info.c for C and cli_info.C for C++, enter:
   bldapp cli_info
The result is an executable file, cli_info.
To run the executable file, enter the executable name:
   cli_info
Building and running embedded SQL applications
  • There are three ways to build the embedded SQL application, tbmod, from the source file tbmod.sqc for C and tbmod.sqC for C++,:
    1. If connecting to the sample database on the same instance, enter:
         bldapp tbmod
    2. If connecting to another database on the same instance, also enter the database name:
         bldapp tbmod database
    3. If connecting to a database on another instance, also enter the user ID and password of the database instance:
         bldapp tbmod database userid password
      The result is an executable file,tbmod
  • There are three ways to run this embedded SQL application:
    1. If accessing the sample database on the same instance, enter the executable name:
         tbmod
    2. If accessing another database on the same instance, enter the executable name and the database name:
         tbmod database
    3. If accessing a database on another instance, enter the executable name, database name, and user ID and password of the database instance:
         tbmod database userid password