Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your profile (name, country/region, and company) is displayed to the public and will accompany any content you post. You may update your IBM account at any time.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

developerWorks Community:

  • Close [x]

DB2 9 Application Development exam 733 prep, Part 4: Embedded SQL programming

Build applications that interact with DB2

Roger E. Sanders (rsanders@netapp.com), Senior Manager - IBM Alliance Engineering, Network Appliance, Inc.
Author1 photo
Roger E. Sanders is a Senior Manager - IBM Alliance Engineering at Network Appliance, Inc. He has been designing and developing databases and database applications for more than 20 years and has been working with DB2 Universal Database since it was first introduced with OS/2 1.3 Extended Edition. He has written articles for IDUG Solutions Journal, Certification Magazine, and developerWorks, presented and taught classes at IDUG and RUG conferences, participated in the development of the DB2 certification exams, writes a regular column for DB2 Magazine and is the author of 9 books on DB2 UDB.
(An IBM developerWorks Master Author, Level 2)

Summary:  This tutorial introduces you to embedded SQL programming and walks you through how to construct an embedded SQL application. This tutorial introduces the process for converting one or more high-level programming language source code files containing embedded SQL into an executable application. This is the fourth in a series of nine tutorials designed to help you prepare for the DB2 Application Developer Certification exam (Exam 733).

View more content in this series

Date:  15 Feb 2007
Level:  Introductory PDF:  A4 and Letter (521 KB | 33 pages)Get Adobe® Reader®

Comments:  

Creating executable applications

The basic process

So far, we have looked at some of the basic steps used to embed SQL statements in high-level programming language source code files, but we have only hinted at how source code files containing embedded SQL statements are converted into executable applications. Once a source code file has been written, the following steps must be performed, in the order shown, before an application that interacts with a DB2 database will be created:

  1. All source code files containing embedded SQL statements must be precompiled. During the precompile process, a source code file containing embedded SQL statements is converted into a source code file that is made up entirely of high-level programming language statements -- the embedded SQL statements themselves are commented out and DB2-specific function calls are stored in their place.

    At the same time, a corresponding package that contains (among other things) the access plans that are to be used to process each static SQL statement embedded in the source code file is also produced. (Access plans contain optimized information that the DB2 Database Manager uses to execute SQL statements; access plans for static SQL statements are produced at precompile time, while access plans for dynamic SQL statements are produced at application runtime.) Packages produced by the SQL precompiler can be stored in the database being used by the precompiler as they are generated, or they can be written to an external bind file and bound to any valid DB2 database later (the process of storing this package in the appropriate database is known as binding). Unless otherwise specified, the SQL precompiler is also responsible for verifying that all database objects, such as tables and columns, that have been referenced in static SQL statements actually exist, and that all application data types used are compatible with their database counterparts. (That's why you need a database connection in order to use the SQL precompiler.)

  2. Once a source code file containing embedded SQL statements has been processed by the SQL precompiler, the source code file produced -- along with any additional source code files needed -- must be compiled by a high-level programming language compiler. This compiler is responsible for converting source code files into object modules that the linker can use to create an executable program.

  3. After all source code files needed to build an application have been successfully compiled, the resulting object modules must be linked with high-level programming language libraries and DB2 libraries to create an executable program. In most cases, the program produced exists as an executable application. However, it may also exist as a shared library or a dynamic link library (DLL) that can be loaded and executed by other executable applications.

  4. If the packages for the files that were processed by the SQL precompiler have not already been bound to the appropriate database, they must be bound using the bind files produced during the precompile process. This is done using a tool known as the DB2 Binder (or simply the Binder).

Figure 1 illustrates the basic process used to convert an embedded SQL source code file to an executable application when deferred binding is used.


Figure 1. Converting an embedded SQL source code file to an executable application
Build process

5 of 8 | Previous | Next

Comments



static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Information Management
ArticleID=195578
TutorialTitle=DB2 9 Application Development exam 733 prep, Part 4: Embedded SQL programming
publish-date=02152007
author1-email=rsanders@netapp.com
author1-email-cc=