NetCOBOL applications can contain sophisticated processing logic that interacts with SQL database systems. The technology that is used to interface to these databases is known as ODBC (Open Database Connectivity), which provides a standard and generic mechanism for any number of applications to access SQL data in a relational matter.
The following sections deal specifically with how to set up the interface between a NetCOBOL SQL program and SQL databases. It concludes with some tips identifying potential runtime problems with NetCOBOL SQL applications.
Note that the samples and screen pictures are from a Microsoft Windows 2000 environment. You may experience some differences on Windows XP, Windows Vista, Windows Server 2003, and Windows Server 2008 systems, but these should be easy to determine.
Typical SQL Program Structure
When you create a NetCOBOL program using embedded SQL that will access one or more SQL databases, your application logic typically goes through the following steps in the following order:
Connect to an SQL database
Declare a cursor (for multiple Selects if desired)
Open the cursor (or if no cursor is desired, simply execute an SQL SELECT statement).
Perform any other desired SQL operations on the data, such as fetching from an open cursor, reading, writing, deleting and updating any specific data.
Closing any open cursors.
Transaction processing, such as committing or rolling back changes.
Disconnecting from SQL databases.
In NetCOBOL, you code your programs using embedded SQL statements and host variables. For information on writing SQL code in NetCOBOL programs, refer to “Chapter 19. Database (SQL)” of the “NetCOBOL User’s Guide”. This chapter covers the information you need to know to set up an environment that supports such programs.
Note that when creating NetCOBOL SQL applications you can access any number of SQL databases available to you within a single application.