Db2 application code, configuration samples, and other examples
This repo contains many sets of sample application code, API usage examples, configuration examples, etc. that are organized into sub-folders according to programming language or sample topic. Some folders contain multiple samples.
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. Contributions to this open-source project are welcomed, see CONTRIBUTING.
Besides the sample application program files, other sample files are also provided in this repo. 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.
The following table shows the sample directories and README files for the main supported programming languages and APIs. 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.
C | README | SOURCE |
C++ | README | SOURCE |
CLI | README | SOURCE |
CLP | README | SOURCE |
Micro Focus COBOL | README | SOURCE |
JDBC | README | SOURCE |
SQLJ | README | SOURCE |
Perl | README | SOURCE |
PHP | README | SOURCE |
SQL Procedures | README | SOURCE |
XML | README | SOURCE |
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:
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 |
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 |
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) |
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:
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:
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.