Building applications in C or C++ using the sample build script (UNIX)
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 filecli_info.c
for C andcli_info.C
for C++, enter:
The result is an executable file,bldapp cli_info
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 filetbmod.sqc
for C andtbmod.sqC
for C++,:- If connecting to the sample database on the same instance, enter:
bldapp tbmod
- If connecting to another database on the same instance, also
enter the database name:
bldapp tbmod database
- If connecting to a database on another instance, also enter the
user ID and password of the database instance:
The result is an executable file,bldapp tbmod database userid password
tbmod
- If connecting to the sample database on the same instance, enter:
- There are three ways to run this embedded SQL application:
- If accessing the
sample
database on the same instance, enter the executable name:tbmod
- If accessing another database on the same instance, enter the
executable name and the database name:
tbmod database
- 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
- If accessing the
- There are three ways to build the embedded SQL application,