IBM Books

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 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 SDK. You can use the sample programs as templates to create your own applications. The file extensions for each supported language, as well as for programs categorized by group, are given in the following tables:

Sample File Extensions by Language
Table 27.

Sample File Extensions by Program Group
Table 28.

The following tables document the sample programs by type:

DB2 API Sample Programs with No Embedded SQL
Table 29.

DB2 API Embedded SQL Sample Programs
Table 30.

Embedded SQL Sample Programs with No DB2 APIs
Table 31.

User-Defined Function Sample Programs
Table 32

DB2 CLI Sample Programs
Table 33.

Java JDBC Sample Programs
Table 34.

Java SQLJ Sample Programs
Table 35.

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

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

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

Command Line Processor (CLP) Sample Programs
Table 39.

Log Management User Exit Programs
Table 40.

Notes:

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

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


Table 27. 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
Fortran samples/fortran .sqf
.f (UNIX)
.for (OS/2)

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


Table 28. Sample File Extensions by Program Group
Sample Group Directory File Extension
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
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++)

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 the OS/2, AIX, and Windows 32-bit operating systems in the cobol subdirectory.

Micro Focus Cobol Samples
Are supplied on all platforms except Linux and Silicon Graphics IRIX. On all other platforms, the Micro Focus COBOL samples are in the cobol_mf subdirectory.

Fortran Samples
Are only supplied on the AIX, HP-UX, Silicon Graphics IRIX, Solaris, and OS/2 platforms.

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 the 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 27, 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.
Note:The sample programs that are shipped with DB2 Universal Database have dependencies on the English version of the sample database and the associated table and column names. If the sample database has been translated into another national language on your version of DB2 Universal Database, you need to update the name of the sample database, and the names of the tables and the columns coded in the supplied sample programs, to the names used in the translated sample database. Otherwise, you will experience problems running the sample programs as shipped.

Currently, the sample database is translated into the following languages:

  • Brazilian Portuguese
  • French
  • Korean
  • Norwegian
  • Simplified Chinese


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]

[ DB2 List of Books | Search the DB2 Books ]