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:
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:
The following tables document the sample programs by type:
Notes:
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: |
|
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.
You can find the C source code for embedded SQL and DB2 API programs in sqllib/samples/c under your database instance directory; the C source code for DB2 CLI programs is in sqllib/samples/cli. For additional information about the programs in the samples tables, refer to the README file in the appropriate samples subdirectory under your DB2 instance. The README file will contain any additional samples that are not listed in this book.
You can find the C source code for embedded SQL and DB2 API programs in %DB2PATH%\samples\c under the DB2 install directory; the C source code for DB2 CLI programs is in %DB2PATH%\samples\cli. The variable %DB2PATH% determines where DB2 is installed. Depending on the drive where DB2 is installed, %DB2PATH% will point to drive:\sqllib. For additional information about the sample programs in the samples tables, refer to the README file in the appropriate %DB2PATH%\samples subdirectory. The README file will contain any additional samples that are not listed in this book.
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.