Application Development Guide


Appendix B. Sample Programs

This section provides information on the sample programs supplied with DB2. All sample programs can be found in the samples subdirectory of the sqllib directory. There is a subdirectory for each supported language.

The sample programs used in this book show examples of embedded SQL statements and API calls in the supported host languages. The sample programs are written to be short and simple. Production applications should check the return codes, and especially the SQLCODE or SQLSTATE from all API calls and SQL statements. For information on handling error conditions, SQLCODEs, and SQLSTATEs, see Diagnostic Handling and the SQLCA Structure. See the Application Building Guide for details on how to install, build, and execute these programs in your environment.

Notes:

  1. This section describes sample programs for the programming languages for all platforms supported by DB2. Not all sample programs have been ported to all platforms or supported programming languages.

  2. DB2 sample programs are provided "as is" without any warranty of any kind. The user, and not IBM, assumes the entire risk of quality, performance, and repair of any defects.

The sample programs come with the DB2 Application Development (DB2 AD) Client. You can use the sample programs as templates to create your own applications.

Sample program file extensions differ for each supported language, and for embedded SQL and non-embedded SQL programs within each language. File extensions may also differ for groups of programs within a language. These different sample file extensions are categorized in the following tables:

Sample File Extensions by Language
Table 38.

Sample File Extensions by Program Group
Table 39.

The following tables document the sample programs by type:

DB2 API Sample Programs with No Embedded SQL
Table 40.

DB2 API Embedded SQL Sample Programs
Table 41.

Embedded SQL Sample Programs with No DB2 APIs
Table 42.

User-Defined Function Sample Programs
Table 43

DB2 CLI Sample Programs
Table 44.

Java JDBC Sample Programs
Table 45.

Java SQLJ Sample Programs
Table 46.

SQL Procedure Sample Programs
Table 47.

ActiveX Data Objects, Remote Data Objects, and Microsoft Transaction Server Sample Programs
Table 48.

Object Linking and Embedding (OLE) Automation Sample Programs
Table 49.

Object Linking and Embedding Database (OLE DB) Table Functions
Table 50.

Command Line Processor (CLP) Sample Programs
Table 51.

Log Management User Exit Programs
Table 52.

Notes:

  1. Table 41 contains programs that have both DB2 APIs and embedded SQL statements. For all DB2 API sample programs, please see both Table 40 and Table 41. For all embedded SQL sample programs (except for Java SQLJ), please see both Table 41 and Table 42.

  2. Table 43 of UDF sample programs does not contain DB2 CLI UDF programs. For these, please see Table 44.


Table 38. Sample File Extensions by Language
Language Directory Embedded SQL Programs Non-embedded SQL Programs
C
samples/c
samples/cli (CLI programs)

.sqc .c
C++ samples/cpp
.sqC (UNIX)
.sqx (Windows & OS/2)


.C (UNIX)
.cxx (Windows & OS/2)

COBOL
samples/cobol
samples/cobol_mf

.sqb .cbl
JAVA samples/java .sqlj .java
REXX samples/rexx .cmd .cmd


Table 39. Sample File Extensions by Program Group
Sample Group Directory File Extension
ADO, RDO, MTS
samples\ADO\VB (Visual Basic)
samples\ADO\VC (Visual C++)
samples\RDO
samples\MTS


.bas .frm .vbp (Visual Basic)
.cpp .dsp .dsw (Visual C++)

CLP samples/clp .db2
OLE
samples\ole\msvb (Visual Basic)
samples\ole\msvc (Visual C++)


.bas .vbp (Visual Basic)
.cpp (Visual C++)

OLE DB samples\oledb .db2
SQL Procedures samples/sqlproc
.db2
.c .sqc (Client Applications)

User Exit samples/c
.cad (OS/2)
.cadsm (UNIX & Windows)
.cdisk (UNIX & Windows)
.ctape (UNIX)

Note:

Directory Delimiters
On UNIX are /. On OS/2 and Windows platforms, are \. In the tables, the UNIX delimiters are used unless the directory is only available on Windows and/or OS/2.

File Extensions
Are provided for the samples in the tables where only one extension exists.

Links to Sample Source Code
Are provided for some (but not all) programs in the samples tables.

Embedded SQL Programs
Require precompilation, except for REXX embedded SQL programs where the embedded SQL statements are interpreted when the program is run.

IBM COBOL samples
Are only supplied for AIX, OS/2, and Windows 32-bit operating systems in the cobol subdirectory.

Micro Focus Cobol Samples
Are only supplied for AIX, HP-UX, OS/2, Solaris Operating Environment, and Windows 32-bit operating systems in the cobol_mf subdirectory.

Java Samples
Are Java Database Connectivity (JDBC) applets, applications, and stored procedures, embedded SQL for Java (SQLJ) applets, applications, and stored procedures, as well as Java UDFs. Java samples are available on all supported DB2 platforms.

REXX Samples
Are only supplied for AIX, OS/2, and Windows NT operating systems.

CLP Samples
Are Command Line Processor scripts that execute SQL statements.

OLE Samples
Are for Object Linking and Embedding (OLE) in Microsoft Visual Basic and Microsoft Visual C++, supplied for Windows 32-bit operating systems only.

ADO, RDO, and MTS Samples
Are ActiveX Data Objects samples in Microsoft Visual Basic and Microsoft Visual C++, and Remote Data Objects and Microsoft Transaction Server samples in Microsoft Visual Basic, supplied for Windows 32-bit operating systems only.

User Exit samples
Are Log Management User Exit programs used to archive and retrieve database log files. The files must be renamed with a .c extension and compiled as C language programs.

You can find the sample programs in the samples subdirectory of the directory where DB2 has been installed. There is a subdirectory for each supported language. The following examples show you how to locate the samples written in C or C++ on each supported platform.

If your platform is not addressed in Table 38, please refer to the Application Building Guide for information specific to your environment.

The sample programs directory is typically read-only on most platforms. Before you alter or build the sample programs, copy them to your working directory.


[ Top of Page | Previous Page | Next Page ]