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 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:
The following tables document the sample programs by type:
Notes:
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: |
|
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 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:
|