beautypg.com

IBM Data Server DB2 User Manual

Page 177

background image

Chapter 4. Deploying applications with DB2

163

Another approach is to compile and link manually from the command line. The
options used for compile and link vary depending on the platforms. A complete
reference can be found at:

http://publib.boulder.ibm.com/infocenter/db2luw/v9r5/topic/com.ibm.db2.luw.apdv
.cli.doc/doc/t0007141.html

In our demonstration, we use the manual method and build the application from
the command line. We use

gcc

, which is a popular compiler on many platforms

and sometimes is included in the default installation. The compile flag

-m64

is

used to inform the compiler that operating system is 64-bit.

The build procedure is as follows:

1. Under the DB2 development environment, create a working folder, for

example,

work

.

2. Save the application code into the folder

work

. Our application is named

itso_cliapp.c

.

3. Compile and link the application in one step:

gcc -o itso_cliapp -m64 -I/home/db2inst1/sqllib/include
-L/home/db2inst1/sqllib/lib -ldb2 itso_cliapp.c

4. Test the application by providing it with the connection information of a known

database. Required arguments include: host name, port number, database
name, user, and password.

A successful connection test is shown in Example 4-9.

Example 4-9 A successful connection using itso_cliapp

db2inst1@mensa:~/work> ./itso_cliapp mensa 50000 itso db2inst1 password

Connecting to the database itso ...

Connected to the database itso.

Disconnecting from the database itso...

In case there is any incorrect connectivity information input, the connection
might fail, and the application will return diagnostic messages as shown in
Example 4-10.

Note: Because we are using a DSN-less connection, the database that we
are connecting to does not have to be existing in local catalog directory.