DB2® provides
build scripts 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. The
script file bldapp contains the commands to build
a CLI application.
It takes up to four parameters, represented inside the script 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 applications
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 extension,
then the embprep script is called to precompile the
program, producing a program file with a .c extension.
About this task
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
Procedure
- Building and Running Embedded SQL Applications There
are three ways to build the embedded SQL application, dbusemx,
from the source file dbusemx.sqc:
- If connecting to the sample database on the same instance, enter:
bldapp dbusemx
- If connecting to another database on the same instance, also
enter the database name:
bldapp dbusemx database
- 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:
- If accessing the sample database on the same instance, simply
enter the executable name:
dbusemx
- If accessing another database on the same instance, enter the
executable name and the database name:
dbusemx database
- 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