Chapter10.Using SQL in an Application Program

Chapter 10. Using SQL in an Application Program

  • Table and view definitions

  • Host variables and structures

  • SQL execution validation

  • Cursors

  • Dynamic SQL

Suppose that you are writing an application program to access data in a DB2 database. When it executes an SQL statement, your program needs to communicate with DB2. When DB2 finishes processing an SQL statement, DB2 sends back a return code, which your program should test to examine the results of the operation.

To communicate with DB2, you need to choose one of these methods:

  • Static SQL

  • Dynamic SQL

  • Open Database Connectivity (ODBC)

  • Java Database Connectivity (JDBC) application support

Static and dynamic SQL statements can be embedded in application source programs. During the compilation process, these statements are extracted from the source program by the DB2 precompiler. The extracted statements are placed in a database request module (DBRM) that is the input to the DB2 bind process to create a package or plan that will be used when the program is executed.

ODBC lets you access data through ODBC function calls in your application. You execute SQL statements by passing them to DB2 through an ODBC function call. ODBC eliminates the need for precompiling and binding your application and increases the portability of your application by using the industry-standard ODBC interface, but the ODBC processor does issue dynamic SQL.

If you are writing your applications in Java, you can use the industry-standard JDBC application support to access DB2. JDBC is similar to ODBC but is designed specifically for use with Java and is therefore a better choice than ODBC for making DB2 calls from Java applications. Java applications can also use embedded SQL statements by following the SQLJ standard.

DB2 for z. OS Version 8 DBA Certification Guide
DB2 for z/OS Version 8 DBA Certification Guide
ISBN: 0131491202
EAN: 2147483647
Year: 2003
Pages: 175
Authors: Susan Lawson © 2008-2017.
If you may any questions please contact us: