Sample files

The sample programs come with the Db2® and IBM® Data Server Client. Not all sample programs are available on all platforms or supported programming languages. You can use the sample programs as templates to create your own applications, and as a learning tool to understand Db2 functionality.

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.

Besides the sample program files, other sample files are provided by Db2 in the samples directories under sqllib/samples (UNIX) and under sqllib\samples (Windows). These include build files and makefiles to compile and link the sample programs, error-checking utility files which are linked in to most sample programs, and various script files to assist in application development. For example, scripts are provided to catalog and uncatalog stored procedures and UDFs in several language sub-directories. Each samples directory has a README file which describes the files contained in the directory.

HTML versions of most sample program source files are provided, accessible in the online documentation. These 'samples in HTML' are linked into the documentation topics to demonstrate the functionality described by them. Keywords, such as SQL statements and Db2 APIs, are hot-linked within the samples in HTML so the user can go directly to the documentation describing them. Most samples in HTML have a link in the comment section at the top of the file to a sample output file showing typical results of running the compiled sample program. Please note that the actual output is, in many cases, machine and platform-dependent, so the output you receive from running the same program might vary.

The following table shows the sample directories and README files for the main supported programming languages/APIs by platform. The README files are hot-linked in the online documentation, and the samples listings within them have hotlinks to the sample file source code. You can also access the sample files in the listed samples directories. For the directory paths, the UNIX-style slashes are used, as in samples/c, except where the directory is for Windows only, as in samples\VB\ADO.
Table 1. Sample README files by platform
Platform —>
Language
AIX Linux Windows
C
samples/c
README README README
C++
samples/cpp
README README README
C#
samples\.NET\cs
n/a n/a README
CLI
samples/cli
README README README
CLP
samples/clp
README README README
IBM COBOL
samples/cobol
README n/a README
Micro Focus COBOL
samples/cobol_mf
README README README
JDBC
samples/java/jdbc
README README README
SQLJ
samples/java/sqlj
README README README
Perl
samples/perl
README README README
PHP
samples/php
README README README
SQL procedures
samples/sqlpl
README README README
Visual Basic
samples\VB\ADO
n/a n/a ReadMe.txt
Visual Basic .NET
samples\.NET\vb
n/a n/a README
Visual Basic .NET
samples\.NET\vb
n/a n/a README
Visual Basic .NET
samples\.NET\vb
n/a n/a README

There are various samples provided for demonstrating Native XML support in Db2. These samples are located in the samples directories under sqllib/samples/xml (UNIX) and under sqllib\samples\xml (Windows). The XML samples come with their own build files, utility files, supporting scripts etc. XQuery samples are all further collected in a separate directory under the parent XML directory. The XQuery as well as other samples demonstrating administrative and application development support are available in various languages.

An overview for the XML samples is provided in a README file in the parent directory. Additional README files are located in the language specific directories; there is a single README file provided in the XQuery directory.

Table 2. README files for XML samples
Readme File - Location Link Description
README
samples/xml
README Parent readme for all XML samples
C
samples/xml/c
README Readme for XML C samples
CLI
samples/xml/cli
README Readme for XML CLI samples
CLP
samples/xml/clp
README Readme for XML CLP samples
JDBC
samples/xml/java/jdbc
README Readme for XML JDBC samples
SQLJ
samples/xml/java/sqlj
README Readme for XML SQLJ samples
XQuery
samples/xml/xquery
README Readme for XML SQLJ samples
Sample program file extensions differ for each supported language, and for embedded SQL and non-embedded SQL programs within each language. File extensions might 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 3.
Sample file extensions by program group
Table 4.
Table 3. Sample file extensions by language
Language Directory Embedded SQL programs Non-embedded SQL programs
C
samples/c
samples/cli (CLI programs)
samples/xml/c
samples/xml/xquery/c
samples/xml/cli (CLI programs)
samples/xml/xquery/cli (CLI programs)
.sqc .c
C++ samples/cpp
.sqC (UNIX)
.sqx (Windows)
.C (UNIX)
.cxx (Windows)
C# samples\.NET\cs   .cs
COBOL
samples/cobol
samples/cobol_mf
.sqb .cbl
Java
samples/java/jdbc
samples/java/sqlj
samples/xml/java/jdbc
samples/xml/xquery/java/jdbc
samples/xml/java/sqlj
samples/xml/xquery/java/sqlj
samples/java/WebSphere
samples/java/plugin
.sqlj .java
Perl samples/perl .pl .pm
PHP samples/php .php
REXX samples/rexx .cmd .cmd
Visual Basic
samples\VB\ADO
samples\VB\MTS
samples\VB\RDO
  .bas .frm .vbp
Visual Basic .NET samples\.NET\vb   .vb
Visual C++ samples\VC\ADO   .cpp .dsp .dsw
Table 4. Sample file extensions by program group
Sample group Directory File Extension
CLP
samples/clp
samples/xml/clp
samples/xml/xquery/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
SQLPL samples/sqlpl
.db2 (SQL Procedure scripts)
.c (CLI Client Applications)
.sqc (embedded C Client Applications)
.java (JDBC Client Applications)
User exit samples/c
.ctsm (UNIX & Windows)
.cdisk (UNIX & Windows)
.ctape (UNIX)
.cxbsa (UNIX)
Note:
Directory delimiters
The directory delimiter on UNIX is a /. On Windows it is a \. In the tables, the UNIX delimiters are used unless the directory is only available on Windows.
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 and Windows 32-bit operating systems in the cobol subdirectory.
Micro Focus COBOL samples
Are only supplied for AIX, Linux, and Windows 32-bit operating systems in the cobol_mf subdirectory.
Java samples
Are Java Database Connectivity (JDBC) applets, applications, and routines, embedded SQL for Java (SQLJ) applets, applications, and routines. Available for demonstrating native XML support as well. Java samples are available on all supported Db2 platforms.
REXX samples
Are only supplied for AIX and Windows 32-bit operating systems.
CLP samples
Are Command Line Processor scripts that execute SQL statements. Also available to show XML and XQuery support.
OLE samples
Are for Object Linking and Embedding (OLE) in Microsoft Visual Basic and Microsoft Visual C++, supplied for Windows operating systems only.
Visual Basic samples
Are ActiveX Data Objects, Remote Data Objects, and Microsoft Transaction Server samples, supplied on Windows operating systems only.
Visual C++ samples
Are ActiveX Data Object samples, supplied on Windows 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.

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.

Structure and design

Most of the Db2 samples in C, CLI, C++, C#, Java, Perl, PHP, Visual Basic ADO, and Visual Basic .NET are organized to reflect an object-based design model of the database components.. The samples are grouped in categories representing different levels of Db2. The level to which a sample belongs is indicated by a two character prefix at the beginning of the sample name. Not all levels are represented in the samples for each Application Programming Interface, but for the samples as a whole, the levels are represented as follows:
prefix
Db2 Level
il
Installation Image Level
cl
Client Level
in
Instance Level
db
Database Level
ts
Table Space Level
tb
Table Level
dt
Data Type Level
The levels show a hierarchical structure. The Installation image level is the top level of Db2. Below this level, a client-level application can access different instances; an instance can have one or more databases; a database has table spaces within which tables exist, and which in turn hold data of different data types.

This design does not include all Db2 samples. The purpose of some samples is to demonstrate different methods for accessing data. These methods are the main purpose of these samples so they are represented by these methods in a similar manner as mentioned previously:

prefix
Programming method
fn
SQL function
sp
Stored procedure
ud
User-defined function
There are other samples not included in this design, such as the XML samples, Log Management User Exit samples, samples in COBOL, Visual C++, REXX, Object Linking and Embedding (OLE) samples, CLP scripts, and SQL Procedures. XML samples are broadly categorized into samples demonstrating native XML administration, application development and XQuery support.
Note: Java, C#, and Visual Basic .NET program names have the first character, and sometimes other characters, in uppercase. Visual Basic ADO samples have some characters in uppercase (but not the first character).