102
DB2 for OS/390 Application Programming Guide and Reference FOR J AVAVersion 5 IBM

Application Programming Guide and Reference

  • Upload
    tess98

  • View
    1.080

  • Download
    0

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: Application Programming Guide and Reference

DB2 for OS/390

Application ProgrammingGuide and ReferenceFOR JAVA™Version 5

IBM

Page 2: Application Programming Guide and Reference
Page 3: Application Programming Guide and Reference

DB2 for OS/390

Application ProgrammingGuide and ReferenceFOR JAVA™Version 5

IBM

Page 4: Application Programming Guide and Reference

First Edition (October 1998)

This edition applies to Version 5 of IBM DATABASE 2 Server for OS/390 (DB2 for OS/390), 5655-DB2, and to allsubsequent releases and modifications until otherwise indicated in new editions.

© Copyright International Business Machines Corporation 1998. All rights reserved.Note to U.S. Government Users — Documentation related to restricted rights — Use, duplication or disclosure issubject to restrictions set forth in GSA ADP Schedule Contract with IBM Corp.

NoteBefore using this information and the product it supports, read the information in“Notices” on page 61.

Page 5: Application Programming Guide and Reference

Contents

Chapter 1. Introduction . . . . . . . . . . . . . . . . . . . . 1Who should read this book . . . . . . . . . . . . . . . . . . . 1How this book is organized . . . . . . . . . . . . . . . . . . . 1Other books you might need . . . . . . . . . . . . . . . . . . . 2Product terminology and citations . . . . . . . . . . . . . . . . . 2How to read the syntax diagrams . . . . . . . . . . . . . . . . . 2How to use the DB2 library . . . . . . . . . . . . . . . . . . . 4

Chapter 2. JDBC application support . . . . . . . . . . . . . . . 7What is JDBC? . . . . . . . . . . . . . . . . . . . . . . . 7

JDBC background information . . . . . . . . . . . . . . . . . 7Advantages of using DB2 JDBC . . . . . . . . . . . . . . . . 7

DB2’s JDBC implementation . . . . . . . . . . . . . . . . . . . 8How does it work? . . . . . . . . . . . . . . . . . . . . . 8Identifying a target data source . . . . . . . . . . . . . . . . . 9Connecting to a data source . . . . . . . . . . . . . . . . . . 10DB2 for OS/390 JDBC driver . . . . . . . . . . . . . . . . . . 10JDBC API . . . . . . . . . . . . . . . . . . . . . . . . 10

Running a JDBC application . . . . . . . . . . . . . . . . . . . 10Getting started . . . . . . . . . . . . . . . . . . . . . . 11

Configuring JDBC . . . . . . . . . . . . . . . . . . . . . . 13Customizing the environment. . . . . . . . . . . . . . . . . . 13

Chapter 3. Writing SQLJ programs for DB2 for OS/390 . . . . . . . . . 15Executing SQL statements in an SQLJ program . . . . . . . . . . . . 16

Including SQL statements in an SQLJ program. . . . . . . . . . . . 16Using Java variables and expressions as host expressions. . . . . . . . 16Including comments. . . . . . . . . . . . . . . . . . . . . 17Handling SQL errors and warnings . . . . . . . . . . . . . . . . 17

Including code to access SQLJ support . . . . . . . . . . . . . . . 18Connecting to a data source . . . . . . . . . . . . . . . . . . . 18Using result set iterators to retrieve rows from a result table . . . . . . . . 20

Using positioned iterators . . . . . . . . . . . . . . . . . . . 21Using named iterators . . . . . . . . . . . . . . . . . . . . 22Using iterators for positioned UPDATE and DELETE operations . . . . . . 24

Controlling the execution of SQL statements . . . . . . . . . . . . . 25An SQLJ sample program. . . . . . . . . . . . . . . . . . . . 26

Chapter 4. Preparing and running SQLJ programs . . . . . . . . . . 29Configuring OpenEdition for SQLJ . . . . . . . . . . . . . . . . . 29Steps in the SQLJ program preparation process . . . . . . . . . . . . 30

Translating SQLJ source code . . . . . . . . . . . . . . . . . 32Compiling an SQLJ program . . . . . . . . . . . . . . . . . . 34Customizing a serialized profile . . . . . . . . . . . . . . . . . 34Binding a plan for an SQLJ program . . . . . . . . . . . . . . . 35

Running SQLJ programs . . . . . . . . . . . . . . . . . . . . 36Diagnosing SQLJ problems . . . . . . . . . . . . . . . . . . . 36

© Copyright IBM Corp. 1998 iii

Page 6: Application Programming Guide and Reference

Collecting trace data . . . . . . . . . . . . . . . . . . . . 36Running diagnosis utilities. . . . . . . . . . . . . . . . . . . 37

Chapter 5. SQLJ statement reference . . . . . . . . . . . . . . . 39Common elements . . . . . . . . . . . . . . . . . . . . . . 40

host-expression . . . . . . . . . . . . . . . . . . . . . . 40implements-clause . . . . . . . . . . . . . . . . . . . . . 41with-clause. . . . . . . . . . . . . . . . . . . . . . . . 42

connection-declaration-clause . . . . . . . . . . . . . . . . . . 43Syntax . . . . . . . . . . . . . . . . . . . . . . . . . 43Description. . . . . . . . . . . . . . . . . . . . . . . . 43Usage notes . . . . . . . . . . . . . . . . . . . . . . . 43

iterator-declaration-clause . . . . . . . . . . . . . . . . . . . . 44Syntax . . . . . . . . . . . . . . . . . . . . . . . . . 44Description. . . . . . . . . . . . . . . . . . . . . . . . 45Usage notes . . . . . . . . . . . . . . . . . . . . . . . 45

executable-clause . . . . . . . . . . . . . . . . . . . . . . 46Syntax . . . . . . . . . . . . . . . . . . . . . . . . . 46Usage notes . . . . . . . . . . . . . . . . . . . . . . . 46

context-clause . . . . . . . . . . . . . . . . . . . . . . . 46Syntax . . . . . . . . . . . . . . . . . . . . . . . . . 46Description. . . . . . . . . . . . . . . . . . . . . . . . 46Usage notes . . . . . . . . . . . . . . . . . . . . . . . 47

statement-clause. . . . . . . . . . . . . . . . . . . . . . . 47Syntax . . . . . . . . . . . . . . . . . . . . . . . . . 47Description. . . . . . . . . . . . . . . . . . . . . . . . 47Usage notes . . . . . . . . . . . . . . . . . . . . . . . 48

assignment-clause . . . . . . . . . . . . . . . . . . . . . . 48Syntax . . . . . . . . . . . . . . . . . . . . . . . . . 48Description. . . . . . . . . . . . . . . . . . . . . . . . 48Usage notes . . . . . . . . . . . . . . . . . . . . . . . 49

Chapter 6. JDBC and SQLJ administration . . . . . . . . . . . . . 51Installing JDBC and SQLJ. . . . . . . . . . . . . . . . . . . . 51

Step 1: Copy and edit the SMP/E jobs . . . . . . . . . . . . . . 51Step 2: Run the allocate job: DSNTJJAE . . . . . . . . . . . . . . 52Optional Step: Allocate HFS data set . . . . . . . . . . . . . . . 52Step 3: Create Hierarchical File System (HFS) structure. . . . . . . . . 52Step 4: Run the receive Job: DSNTJJRC. . . . . . . . . . . . . . 53Step 5: Run the apply job: DSNTJJAP . . . . . . . . . . . . . . 53Step 6: Run the accept job: DSNTJJAC . . . . . . . . . . . . . . 53Step 7: Run the SQLJ allocate jobs . . . . . . . . . . . . . . . 53Step 8: Install SQLJ modules . . . . . . . . . . . . . . . . . 53

JDBC and SQLJ security model . . . . . . . . . . . . . . . . . . 53How are authorization IDs established? . . . . . . . . . . . . . . 53DB2 attachment types . . . . . . . . . . . . . . . . . . . . 54

JDBC and SQLJ multiple context support . . . . . . . . . . . . . . 54Connecting when multiple context support is not enabled . . . . . . . . 55Connecting when multiple context support is enabled . . . . . . . . . 55Connection sharing . . . . . . . . . . . . . . . . . . . . . 56

iv Application Programming Guide and Reference for Java™

Page 7: Application Programming Guide and Reference

Appendix. Selected sqlj.runtime classes and interfaces . . . . . . . . . 57sqlj.runtime.ExecutionContext class . . . . . . . . . . . . . . . . 57sqlj.runtime.ForUpdate interface. . . . . . . . . . . . . . . . . . 58sqlj.runtime.NamedIterator interface . . . . . . . . . . . . . . . . 58sqlj.runtime.PositionedIterator interface . . . . . . . . . . . . . . . 59

Notices . . . . . . . . . . . . . . . . . . . . . . . . . . 61Programming interface information . . . . . . . . . . . . . . . . . 62Trademarks . . . . . . . . . . . . . . . . . . . . . . . . 63

Glossary . . . . . . . . . . . . . . . . . . . . . . . . . 65

Bibliography . . . . . . . . . . . . . . . . . . . . . . . . 81

Index . . . . . . . . . . . . . . . . . . . . . . . . . . 89

Contents v

Page 8: Application Programming Guide and Reference

vi Application Programming Guide and Reference for Java™

Page 9: Application Programming Guide and Reference

Chapter 1. Introduction

This book describes DB2 for OS/390 Java Edition, a feature of DB2 for OS/390 that letsyou access relational databases from Java application programs.

Who should read this book

This book is for DB2 application developers who are familiar with Structured QueryLanguage (SQL) and who know the Java programming language.

How this book is organized

This book is organized as follows:

v “Chapter 1. Introduction” describes this book and gives general information aboutVersion 5 of DB2 for OS/390.

v “Chapter 2. JDBC application support” on page 7 describes how to write JDBCprograms for DB2 for OS/390. It also describes how to prepare and execute JDBCprograms and how to set up the OS/390 OpenEdition environment for running JDBCprograms.

v Chapters 3, 4, and 5 describe DB2 support for SQLJ:

– “Chapter 3. Writing SQLJ programs for DB2 for OS/390” on page 15 introducesSQLJ and describes the basic elements of an SQLJ application program.

– “Chapter 4. Preparing and running SQLJ programs” on page 29 describes how toprepare and execute SQLJ programs and how to set up the OS/390 OpenEditionenvironment for running SQLJ programs.

– “Chapter 5. SQLJ statement reference” on page 39 gives the syntax and adescription of each SQLJ clause.

v “Chapter 6. JDBC and SQLJ administration” on page 51 discusses the followingtopics that are related to JDBC and SQLJ administration on DB2 for OS/390:

– How to install JDBC and SQLJ

– How JDBC and SQLJ authorization works

– How JDBC and SQLJ multiple context support works

v The appendix contains information on the methods of the sqlj.runtime package thatyou can call in your SQLJ programs.

Located after the appendixes are:

v Legal notices

v A glossary of terms and abbreviations used in the book

v A bibliography of other books that might be useful

v An index

© Copyright IBM Corp. 1998 1

Page 10: Application Programming Guide and Reference

Other books you might need

This book describes DB2 interfaces to Java, rather than the Java programminglanguage itself. For information on the OS/390 implementation of the Java language,see the Web site for Java for OS/390:

http://www.s390.ibm.com/java

DB2 for OS/390 is one of several IBM relational database management systems. Eachof these systems understands its own variety of SQL. This book discusses only thevariety that is used by DB2 for OS/390. Other IBM books describe the other varieties.For a list of these books, see “Bibliography” on page 81.

If DB2 for OS/390 is the only product you plan to use, you should also refer to SQLReference, which is an encyclopedic reference to the syntax and semantics of everySQL statement in DB2 for OS/390. For SQL fundamentals and concepts, see Chapter 2of SQL Reference.

If you intend to develop applications that adhere to the definition of IBM SQL, see IBMSQL Reference for more information.

Product terminology and citations

In this book, DB2 Server for OS/390 is referred to as "DB2 for OS/390." In cases wherethe context makes the meaning clear, DB2 for OS/390 is referred to as "DB2." Whenthis book refers to other books in this library, a short title is used. (For example, "SeeSQL Reference" is a citation to IBM DATABASE 2 Server for OS/390 SQL Reference.)

The following terms are used as indicated:

DB2 Represents either the DB2 licensed program or a particular DB2 subsystem.

MVS Represents the MVS/Enterprise Systems Architecture (MVS/ESA) element ofOS/390.

How to read the syntax diagrams

The following rules apply to the syntax diagrams that are used in this book:

v Read the syntax diagrams from left to right, from top to bottom, following the path ofthe line.

The ÊÊ─── symbol indicates the beginning of a statement.

The ───Ê symbol indicates that the statement syntax is continued on the next line.

The Ê─── symbol indicates that a statement is continued from the previous line.

The ───ÊÍ symbol indicates the end of a statement.

Diagrams of syntactical units other than complete statements start with the Ê───symbol and end with the ───Ê symbol.

2 Application Programming Guide and Reference for Java™

Page 11: Application Programming Guide and Reference

v Required items appear on the horizontal line (the main path).

ÊÊ required_item ÊÍ

v Optional items appear below the main path.

ÊÊ required_itemoptional_item

ÊÍ

If an optional item appears above the main path, that item has no effect on theexecution of the statement and is used only for readability.

ÊÊoptional_item

required_item ÊÍ

v If you can choose from two or more items, they appear vertically, in a stack.

If you must choose one of the items, one item of the stack appears on the main path.

ÊÊ required_item required_choice1required_choice2

ÊÍ

If choosing one of the items is optional, the entire stack appears below the mainpath.

ÊÊ required_itemoptional_choice1optional_choice2

ÊÍ

If one of the items is the default, it appears above the main path and the remainingchoices are shown below.

ÊÊ required_itemdefault_choice

optional_choiceoptional_choice

ÊÍ

v An arrow returning to the left, above the main line, indicates an item that can berepeated.

ÊÊ required_item ·

.

repeatable_item ÊÍ

If the repeat arrow contains a comma, you must separate repeated items with acomma.

Chapter 1. Introduction 3

Page 12: Application Programming Guide and Reference

ÊÊ required_item ·

,

repeatable_item ÊÍ

A repeat arrow above a stack indicates that you can repeat the items in the stack.

v Keywords appear in uppercase (for example, FROM). They must be spelled exactly asshown. Variables appear in all lowercase letters (for example, column-name). Theyrepresent user-supplied names or values.

v If punctuation marks, parentheses, arithmetic operators, or other such symbols areshown, you must enter them as part of the syntax.

How to use the DB2 library

Titles of books in the library begin with DB2 for OS/390 Version 5. However, referencesfrom one book in the library to another are shortened and do not include the productname, version, and release. Instead, they point directly to the section that holds theinformation. For a complete list of books in the library, and the sections in each book,see the bibliography at the back of this book.

The most rewarding task associated with a database management system is askingquestions of it and getting answers, the task we call end use. Other tasks are alsonecessary—defining the parameters of the system, putting the data in place, and so on.The tasks associated with DB2 are grouped into the following major categories (butsupplemental information relating to all of the below tasks for new releases of DB2 canbe found in Release Guide):

Installation: If you are involved with DB2 only to install the system, Installation Guidemight be all you need.

If you will be using data sharing then you also need Data Sharing: Planning andAdministration, which describes installation considerations for data sharing.

End use: End users issue SQL statements to retrieve data. They can also insert,update, or delete data, with SQL statements. They might need an introduction to SQL,detailed instructions for using SPUFI, and an alphabetized reference to the types ofSQL statements. This information is found in Application Programming and SQL Guideand SQL Reference.

End users can also issue SQL statements through the Query Management Facility(QMF) or some other program, and the library for that program might provide all theinstruction or reference material they need. For a list of some of the titles in the QMFlibrary, see the bibliography at the end of this book.

Application Programming: Some users access DB2 without knowing it, usingprograms that contain SQL statements. DB2 application programmers write those

4 Application Programming Guide and Reference for Java™

Page 13: Application Programming Guide and Reference

programs. Because they write SQL statements, they need Application Programming andSQL Guide, SQL Reference, and Call Level Interface Guide and Reference, just as endusers do.

Application programmers also need instructions on many other topics, such as how to:

v Transfer data between DB2 and a host program—written in COBOL, C, orFORTRAN, for example

v Prepare to compile a program that embeds SQL statements

v Process data from two systems simultaneously, such as DB2 and IMS or DB2 andCICS

v Write distributed applications across operating systems

v Write applications that use DB2 Call Level Interface to access DB2 servers

v Write applications that use Open Database Connectivity (ODBC) to access DB2servers

v Write applications in the Java programming language to access DB2 servers

The material needed for writing a host program containing SQL is in ApplicationProgramming and SQL Guide and in this book. The material needed for writingapplications that use DB2 Call Level Interface or ODBC to access DB2 servers is inCall Level Interface Guide and Reference. For handling errors, see Messages andCodes .

Information about writing applications on different operating systems can be found inDistributed Relational Database Architecture: Application Programming Guide.

System and Database Administration: Administration covers almost everything else.Administration Guide divides those tasks among the following sections:

v Section 2 (Volume 1) of Administration Guide discusses the decisions that must bemade when designing a database and tells how to bring the design into being bycreating DB2 objects, loading data, and adjusting to changes.

v Section 3 (Volume 1) of Administration Guide describes ways of controlling access tothe DB2 system and to data within DB2, to audit aspects of DB2 usage, and toanswer other security and auditing concerns.

v Section 4 (Volume 1) of Administration Guide describes the steps in normalday-to-day operation and discusses the steps one should take to prepare forrecovery in the event of some failure.

v Section 5 (Volume 2) of Administration Guide explains how to monitor theperformance of the DB2 system and its parts. It also lists things that can be done tomake some parts run faster.

In addition, the appendixes in Administration Guide contain valuable information on DB2sample tables, National Language Support (NLS), writing exit routines, interpreting DB2trace output, and character conversion for distributed data.

Chapter 1. Introduction 5

Page 14: Application Programming Guide and Reference

If you are involved with DB2 only to design the database, or plan operationalprocedures, you need Administration Guide. If you also want to carry out your ownplans by creating DB2 objects, granting privileges, running utility jobs, and so on, youalso need:

v SQL Reference, which describes the SQL statements you use to create, alter, anddrop objects and to grant and revoke privileges

v Utility Guide and Reference, which explains how to run utilities

v Command Reference, which explains how to run commands

If you will be using data sharing, you need Data Sharing: Planning and Administration,which describes how to plan for and implement data sharing.

Additional information about system and database administration can be found inMessages and Codes, which lists messages and codes that are issued by DB2, withexplanations and suggested responses.

Diagnosis: Diagnosticians detect and describe errors in the DB2 program. They mightalso recommend or apply a remedy. The documentation for this task is in DiagnosisGuide and Reference and Messages and Codes.

6 Application Programming Guide and Reference for Java™

Page 15: Application Programming Guide and Reference

Chapter 2. JDBC application support

This chapter explains DB2 for OS/390’s support for applications using JavaSoftTM JavaDatabase Connectivity (JDBC) interfaces to access DB2 data. It provides an overviewthat explains what JDBC is, more detailed information about DB2 for OS/390’simplementation of JDBC, and guidelines for running a Java program and configuring theJDBC environment.

What is JDBC?

JDBC is a Java application programming interface (API) that Java applications use toaccess any relational database. DB2 for OS/390’s support for JDBC enables you towrite Java applications that access local DB2 data or remote relational data on a serverthat supports DRDA.

JDBC background information

To understand JDBC, knowing about its purpose and background is helpful. SunMicrosystem’sTM JavaSoft developed the specifications for a set of APIs that allow Javaapplications to access relational data. The purpose of the APIs is to provide a genericinterface for writing platform-independent applications that can access any SQLdatabase. The APIs are defined within 16 classes that support basic SQL functionalityfor connecting to a database, executing SQL statements, and processing results.Together, these interfaces and classes represent the JDBC capabilities by which a Javaapplication can access relational data.

Relationship between JDBC and ODBC

A very close relationship exists between JDBC and ODBC. JDBC is based on theX/Open SQL Call Level Interface (CLI) specification which also served as the basis forODBC. For more information about ODBC and its relationship to DB2 CLI (which isbased on the X/Open CLI and ODBC specifications), see Section 2 of Call LevelInterface Guide and Reference.

Each JDBC class has one or more methods that implement the operations to supportthe class interface. Almost all of the methods within the JDBC classes map to one ormore of the ODBC APIs. The ODBC APIs are procedural, whereas the JDBC classesare within the domain of the object-oriented model of the Java programming language.

Advantages of using DB2 JDBC

DB2 JDBC offers a number of advantages for accessing DB2 data:

v Using the Java language, you can write an application on any platform and execute iton any platform to which the Java Development Kit (JDK) is ported.

v JDBC combines the benefit of running your applications in an OS/390 environmentwith the portability and ease of writing Java applications.

© Copyright IBM Corp. 1998 7

Page 16: Application Programming Guide and Reference

v The ability to develop an application once and execute it anywhere offers thepotential benefits of reduced development, maintenance, and systems managementcosts, and flexibility in supporting diverse hardware and software configurations.

v The JDBC interface offers the ability to change between drivers and access a varietyof databases without recoding your Java program.

v JDBC applications do not require precompiles or binds.

DB2’s JDBC implementation

DB2 for OS/390 supports the JDBC specification: JDBC: A Java SQL API. You candownload the specification from the JDBC Web site: http://splash.javasoft.com/jdbc. Youshould familiarize yourself with the specification to understand how to use the JDBCAPIs. Documentation that includes detailed information about each of the JDBC APIinterfaces, classes, and exceptions is also available at this Web site.

DB2 for OS/390 requires the JDK for OS/390 (Version 1.1.1 or higher). The contents ofthe JDK include a Java compiler, Java Virtual Machine (JVM), and Java Debugger. Youcan learn more about the JDK from the Java for OS/390 Web site:http://www.s390.ibm.com/java.

How does it work?

Figure 1 on page 9 shows how a Java application connects to the DB2 for OS/390JDBC driver.

8 Application Programming Guide and Reference for Java™

Page 17: Application Programming Guide and Reference

A Java application executes under the JVM. The Java application first loads the JDBCdriver, in this case the DB2 for OS/390 JDBC driver, and subsequently connects to thelocal DB2 subsystem or a remote DRDA application server (by invoking theDriverManager.getConnection method, described in “Getting started” on page 11).

Identifying a target data source

The Java application identifies the target data source it wants to connect to by passinga database Uniform Resource Locator (URL) to the DriverManager.

The basic structure for the URL is:

jdbc:<subprotocol>:<subname>

The URL values for a DB2 for OS/390 data source are specified as follows:

jdbc:db2os390:<location>

If location-name is not the local site, location-name must be defined inSYSIBM.LOCATIONS. If location-name is the local site, location-name must have beenspecified in field DB2 LOCATION NAME of the DISTRIBUTED DATA FACILITY panelduring DB2 installation.

Figure 1. Java application flow

Chapter2.JDBCapplicationsupport9

Page 18: Application Programming Guide and Reference

Connecting to a data source

When the application attempts a connection to a data source, it requests ajava.sql.Connection implementation from the DriverManager (part of the java.sqlpackage). The DriverManager searches all of the known java.sql.Driverimplementations for a driver that is capable of accepting the database URL. It theninvokes the first JDBC driver that supports the subprotocol that is specified in the URLand is registered with the DriverManager.

In this case, the DB2 for OS/390 driver (which is registered with the DriverManager)accepts the URL, and returns a java.sql.Connection implementation that representsthe database connection.

DB2 for OS/390 JDBC driver

The DB2 for OS/390 JDBC driver is implemented as a type 1 driver. It provides Javaapplication support only. A type 1 driver is one of four types of JDBC drivers. This driveris implemented as a JDBC-ODBC bridge, which enables the use of existing ODBCdrivers by Java programs. It translates all of the JDBC method calls into ODBC functioncalls, which process database requests.

Included with the driver is the ibm.sql package. This package is the DB2 for OS/390implementation of the java.sql JDBC API package. The package includes all of theJDBC classes, interfaces, and exceptions.

JDBC API

The JDBC API consists of the abstract Java interfaces that an application program usesto access databases, execute SQL statements, and process the results. The four maininterfaces that perform these functions are:

v The DriverManager class loads drivers and creates database connections.

v The Connection interface supports the connection to a specific database.

v The Statement interface supports all SQL statement execution. This interface has twounderlying interfaces:

– The PreparedStatement interface supports any SQL statement containing inputparameter markers.

– The CallableStatement interface supports the invocation of a stored procedureand allows the application to retrieve output parameters.

v The ResultSet interface provides access to the results that an executed statementgenerates.

Running a JDBC application

Like ODBC, JDBC is a dynamic SQL interface. Writing a JDBC application is similar towriting a C application using ODBC to access a database.

10 Application Programming Guide and Reference for Java™

Page 19: Application Programming Guide and Reference

When you create a Java application that uses the JDBC interfaces, you import thejava.sql package and invoke methods according to the JDBC specification.

Getting started

When you begin coding your program, use the sample program, sample01.java shownin Figure 2 on page 12, as a guide. The sample JDBC application code is located in asamples subdirectory. Assuming the driver is installed in /usr/lpp/db2, the samplessubdirectory is:

/usr/lpp/db2/db2510/samples

Chapter 2. JDBC application support 11

Page 20: Application Programming Guide and Reference

�1�import java.sql.*;

class sample01 {static {

try {// register the DB2 for OS/390 driver with DriverManager

�2� Class.forName("ibm.sql.DB2Driver");} catch (ClassNotFoundException e) {

e.printStackTrace();}

}public static void main(String argv[]) {

try {System.out.println("**** JDBC Entry within class sample01.");

�3� // Create the connection// You must change the following URL to match the location name// of your local DB2 for OS/390.// The URL is in the form of "jdbc:db2os390:location_name"String url = "jdbc:db2os390:st11db2g";Connection con = DriverManager.getConnection (url);System.out.println("**** JDBC Connection to DB2 for OS/390.");

�4� // Create the StatementStatement stmt = con.createStatement();System.out.println("**** JDBC Statement Created");

�5� // Execute a Query and generate a ResultSet instance// The query is a SELECT from SYSIBM.SYSTABLESResultSet rs = stmt.executeQuery("SELECT * FROM SYSIBM.SYSTABLES");System.out.println("**** JDBC Result Set Created");

�6� // Print all of the table names to sysoutwhile (rs.next()) {String s = rs.getString(1);System.out.println("Table NAME = " + s);

}System.out.println("**** JDBC Result Set output completed");

�7� // Close the statementstmt.close();System.out.println("**** JDBC Statement Closed");

�8� // Close the connectioncon.close();System.out.println("**** JDBC Disconnect from DB2 for OS/390.");

} catch( Exception e ) {e.printStackTrace();

}System.out.println("**** JDBC Exit from class sample01 - no Errors.");

}}

Figure 2. Sample Java application

12 Application Programming Guide and Reference for Java™

Page 21: Application Programming Guide and Reference

Notes to Figure 2 on page 12:

�1� The first statement imports the appropriate Java package, java.sql.�2� The Class.forName method loads the appropriate JDBC driver, in this case, DB2 for

OS/390 JDBC driver (ibm.sql.DB2Driver) and registers it with the DriverManager.�3� The getConnection method creates a Connection instance to connect to the database,

specifying the location with a URL and using the DB2 subprotocol (as defined in theJDBC specification and explained in “Connecting to a data source” on page 10). Youmust modify the URL in the sample01.java application to match the location name ofyour local DB2 for OS/390.

�4� The createStatement method creates a Statement instance.�5� The executeQuery method executes a query and generates a ResultSet instance.�6� The next() method on the ResultSet instance advances the iterator to successive rows

of the result set. For each row, the getString method is called to retrieve column 1.�7� close() closes the statement and frees all resources associated with the statement.�8� close() closes the connection and frees all resources associated with the connection.

After coding your program, compile it as you would any other Java program. Noprecompile or bind steps are required to run a Java program.

Configuring JDBC

This section explains the environmental variables you must set to customize yourenvironment, and the JDBC features that DB2 for OS/390 supports. “Chapter 6. JDBCand SQLJ administration” on page 51 describes how to install DB2 JDBC.

Customizing the environment

You must set environmental variables to run a JDBC program. You need to customizeyour environment to include the data sets, dynamic load libraries, and JDBC class filethat is included in the JDBC driver. Modify the following OpenEdition environmentalvariables:

STEPLIBModify STEPLIB to include the SDSNEXIT and SDSNLOAD data sets. These datasets are required to execute the DB2 JDBC driver. For example:

export STEPLIB=DSN510.SDSNEXIT:DSN510.SDSNLOAD

LIBPATH and LD_LIBRARY_PATHThe JDBC driver contains two dynamic load libraries:

v libdb2jdbc.so (for java)

v libdb2jdbc_g.so (for java_g)

Under the direction of IBM Service, you might be asked to use java_g toobtain a JDBC diagnosis trace to aid in diagnosing problems. If you aredirected to use an ODBC trace for diagnosis purposes, see Chapter 7 of CallLevel Interface Guide and Reference for DB2 CLI trace information.

Chapter 2. JDBC application support 13

Page 22: Application Programming Guide and Reference

Modify LIBPATH and LD_LIBRARY_PATH to include the directory that containsthese DLLs. Assuming the driver is installed in /usr/lpp/db2, modify LIBPATHand LD_LIBRARY_PATH, respectively, as follows:

export LIBPATH=/usr:/usr/lib:/usr/lpp/db2/db2510/lib

export LD_LIBRARY_PATH=/usr/lpp/db2/db2510/lib

CLASSPATHModify CLASSPATH to include the JDBC class file, db2jdbcclasses.zip, whichcontains the JDBC classes. Assuming the JDBC driver is installed in/usr/lpp/db2, modify CLASSPATH as follows:

export CLASSPATH=/usr/lpp/db2/db2510/classes/db2jdbcclasses.zip

DSNAOINIBecause DB2 JDBC is implemented as a type 1 driver, DB2 JDBC isdependent on DB2 for OS/390 CLI support. It might be necessary to overridesome of the configuration defaults that DB2 CLI support uses. See Section 4of Call Level Interface Guide and Reference for information about the DB2 CLIinitialization file (DSNAOINI).

14 Application Programming Guide and Reference for Java™

Page 23: Application Programming Guide and Reference

Chapter 3. Writing SQLJ programs for DB2 for OS/390

SQLJ provides support for embedded static SQL in Java applications and applets.SQLJ was initially developed by Oracle, Tandem, and IBM to complement the dynamicSQL JDBC model with a static SQL model.

In general, Java applications use JDBC for dynamic SQL and SQLJ for static SQL.However, because SQLJ includes JDBC 1.2, an application program can create a JDBCconnection and then use that connection to execute dynamic SQL statements throughJDBC and embedded static SQL statements through SQLJ.

The SQLJ specification has been submitted to ANSI for standardization (ANSIdocument number dpANS X3.135.10). The SQLJ specification consists of three parts:

v Part 0 specifies the SQLJ language syntax and semantics for embedded SQLstatements in a Java application.

v Part 1 specifies extensions that define:

– Installation of Java classes in an SQL database

– Invocation of static methods as stored procedures and user-defined functions

v Part 2 specifies extensions for accessing Java classes as SQL distinct types.

DB2 for OS/390 support for SQLJ includes part 0 of the SQLJ specification.

Some of the major differences between SQLJ and JDBC are:

v SQLJ follows the static SQL model, and JDBC follows the dynamic SQL model.

v SQLJ source programs are smaller than equivalent JDBC programs, because certaincode that the programmer must include in JDBC programs is generated automaticallyby SQLJ.

v SQLJ does data type checking during the program preparation process and enforcesstrong typing between table columns and Java host expressions. JDBC passesvalues to and from SQL tables without compile-time data type checking.

v In SQLJ programs, you can embed Java host expressions in SQL statements. JDBCrequires a separate call statement for each bind variable and specifies the binding byposition number.

v SQLJ provides the advantages of static SQL authorization checking. With SQLJ, theauthorization ID under which SQL statements execute is the plan or package owner.DB2 checks table privileges at bind time. Because JDBC uses dynamic SQL, theauthorization ID under which SQL statements execute is not known until run time, sono authorization checking of table privileges can occur until run time.

This chapter and the following two chapters explain DB2 for OS/390 support for SQLJ.This chapter gives you the information that you need to write SQLJ programs that runon DB2 for OS/390. Subsequent chapters describe how to prepare SQLJ programs forexecution and provide detailed syntax for the components of SQLJ.

The following topics are discussed in this chapter:

v “Executing SQL statements in an SQLJ program” on page 16

© Copyright IBM Corp. 1998 15

Page 24: Application Programming Guide and Reference

v “Including code to access SQLJ support” on page 18

v “Connecting to a data source” on page 18

v “Using result set iterators to retrieve rows from a result table” on page 20

v “Controlling the execution of SQL statements” on page 25

v “An SQLJ sample program” on page 26

Executing SQL statements in an SQLJ program

This section discusses the following basic information about writing an SQLJ program:

v How to include SQL statements, host variables, and comments in the program

v Which SQL statements are valid in an SQLJ program

v How to do error handling

Including SQL statements in an SQLJ program

In an SQLJ program, all statements that are used for database access are in SQLJclauses. SQLJ clauses that contain SQL statements are called executable clauses. Anexecutable clause begins with the characters #sql and contains an SQL statement thatis enclosed in curly brackets. The SQL statement itself has no terminating character. Anexample of an executable clause is:

#sql {DELETE FROM EMP};

“executable-clause” on page 46 contains a list of the SQL statements that you caninclude in an SQLJ program. An executable clause can appear anywhere in a programthat a Java statement can appear.

Using Java variables and expressions as host expressions

To pass data between a Java application program and DB2, use host expressions. AJava host expression is a Java simple identifier or complex expression, preceded by acolon. The result of a complex expression must be a single value. When you use a hostexpression as a parameter in a stored procedure call, you can follow the colon with theIN, OUT, or INOUT parameter, which indicates whether the host expression is intendedfor input, output, or both. The IN, OUT, or INOUT value must agree with the value youspecify in the stored procedure definition in catalog table SYSIBM.SYSPROCEDURES.

The following SQLJ clause uses a host expression that is a simple Java variable namedempname:

#sql {SELECT LASTNAME INTO :empname FROM EMP WHERE EMPNO='000010'};

The following SQLJ clause calls stored procedure A and uses a simple Java variablenamed EMPNO as an input or output parameter:

#sql {CALL A (INOUT :EMPNO)};

16 Application Programming Guide and Reference for Java™

Page 25: Application Programming Guide and Reference

SQLJ evaluates host expressions from left to right before DB2 processes the SQLstatements that contain them. For example, for the following SQL clause, Javaincrements variable x before DB2 executes the SELECT statement:

#sql {SELECT ACTDESC INTO :hvactdsc WHERE ACTNO=:(x++)};

Similarly, in the following example, Java determines array element y[i] and decrements ibefore DB2 executes the SELECT statement:

#sql {SELECT ACTDESC INTO :hvactdsc WHERE ACTNO=:(y[i--])};

In an executable clause, host expressions, which are Java tokens, are case sensitive.

Including comments

To include comments in an SQLJ program, use either Java comments or SQLcomments.

v Java comments are denoted by /* */ or //. You can include Java comments outsideSQLJ clauses, wherever the Java language permits them. Within an SQLJ clause,use Java comments in host expressions.

v SQL comments are denoted by * at the beginning of a line or -- anywhere on a linein an SQL statement. You can use SQL comments in executable clauses, anywhereexcept in host expressions.

Handling SQL errors and warnings

SQLJ clauses use the JDBC class java.sql.SQLException for error handling. SQLJgenerates an SQLException when an SQL statement returns a negative SQLCODE.You can use the getErrorCode method to retrieve SQLCODEs and the getSQLStatemethod to retrieve SQLSTATEs.

To handle SQL errors in your SQLJ application, import the java.sql.SQLExceptionclass, and use the Java error handling try/catch blocks to modify program flow whenan SQL error occurs. For example:

try {#sql {SELECT LASTNAME INTO :empnameFROM EMP WHERE EMPNO='000010'};

}catch(SQLException e) {System.out.println("SQLCODE returned: " + e.getErrorCode());

}

Because SQL warnings do not generate SQLExceptions, you must invoke theGetWarnings method after you execute an SQL clause to check for an SQL warning.GetWarnings returns the first warning code that an SQL statement generates.

Before you can execute GetWarnings for an SQL clause, you need to set up anexecution context for that SQL clause. See “Controlling the execution of SQL

Chapter 3. Writing SQLJ programs for DB2 for OS/390 17

Page 26: Application Programming Guide and Reference

statements” on page 25 for information on how to set up an execution context. Thefollowing example demonstrates how to retrieve an SQL warning code for an SQLclause with execution context execCtx:

SQLWarning SQLWarn;#sql [execCtx] {SELECT LASTNAME INTO :empnameFROM EMP WHERE EMPNO='000010'};

if (SQLWarn = execCtx.GetWarnings() != null) thenSystem.out.println("SQLWarning " + SQLWarn);

Including code to access SQLJ support

Before you can execute any SQLJ clauses in your application program, you mustinclude code to accomplish these tasks:

v Import the Java packages for SQLJ run-time support and the JDBC interfaces thatare used by SQLJ

v Load the DB2 for OS/390 SQLJ JDBC driver, which is the SQLJ implementation ofJDBC 1.2 function, and register the SQLJ JDBC driver with the DriverManager

To import the Java packages for SQLJ and JDBC, include these lines in yourapplication program:

import sqlj.runtime.*; // SQLJ runtime supportimport java.sql.*; // JDBC interfaces

To load the DB2 for OS/390 SQLJ JDBC driver and register it with the DriverManager,invoke method Class.forName with an argument ofCOM.ibm.db2os390.sqlj.jdbc.DB2SQLJDriver. For example:

try {Class.forName("COM.ibm.db2os390.sqlj.jdbc.DB2SQLJDriver");

}catch (ClassNotFoundException e) {

e.printStackTrace();}

Connecting to a data source

In an SQLJ application, as in any other DB2 application, you must be connected to adata source before you can execute SQL statements. A data source in DB2 for OS/390is a DB2 location name.

If you do not specify any data sources in an SQLJ program that you run on DB2 forOS/390, DB2 connects you to the local DB2 subsystem automatically. If you want toexecute an SQL statement at another data source, you must specify a connectioncontext, enclosed in square brackets, at the beginning of the execution clause thatcontains the SQL statement. For example, the following SQL clause executes anUPDATE statement at the data source that is associated with connection contextmyconn:

18 Application Programming Guide and Reference for Java™

Page 27: Application Programming Guide and Reference

#sql [myconn] {UPDATE DEPT SET MGRNO=:hvmgr WHERE DEPTNO=:hvdeptno};

A connection context is an instance of a connection context class. To define theconnection context class and set up the connection context, use one of the followingmethods before you specify the connection context in any SQL statements:

v Connection method 1:

1. Execute a type of SQLJ clause called a connection declaration clause togenerate a connection context class.

2. Invoke the constructor for the connection context class with the followingarguments:

– A string that specifies the location name that is associated with the datasource. That argument has the form:

jdbc:db2os390sqlj:location-name

If location-name is not the local site, location-name must be defined inSYSIBM.LOCATIONS. If location-name is the local site, location-name musthave been specified in field DB2 LOCATION NAME of the DISTRIBUTEDDATA FACILITY panel during DB2 installation.

– A boolean that specifies whether autoCommit is on or off for the connection.

For example, suppose that you want to use the first method to set up connectioncontext myconn to access data at a data source that is associated with locationNEWYORK. For this connection, you want autoCommit to be off. First, execute aconnection declaration clause to generate a connection context class:

#sql context ctx;

Then invoke the constructor for generated class ctx with argumentsjdbc:db2os390sqlj:NEWYORK and false:

ctx myconn=new ctx("jdbc:db2os390sqlj:NEWYORK",false);

v Connection method 2:

1. Execute a connection declaration clause to generate a connection context class.

2. Invoke the JDBC java.sql.DriverManager.getConnection method. The argumentfor java.sql.DriverManager.getConnection is a string that specifies the locationname that is associated with the data source. That argument has the form:

jdbc:db2os390sqlj:location-name

If location-name is not the local site, location-name must be defined inSYSIBM.LOCATIONS. If location-name is the local site, location-name must havebeen specified in field DB2 LOCATION NAME of the DISTRIBUTED DATAFACILITY panel during DB2 installation. The invocation returns an instance ofclass Connection, which represents a JDBC connection to the data source.

3. The default state of autoCommit for a JDBC connection is on. To disableautoCommit, invoke the setAutoCommit method with an argument of false.

4. Invoke the constructor for the connection context class. For the argument of theconstructor, use the JDBC connection that results from invokingjava.sql.DriverManager.getConnection.

Chapter 3. Writing SQLJ programs for DB2 for OS/390 19

Page 28: Application Programming Guide and Reference

To use the second method to set up connection context myconn to access data atthe data source associated with location NEWYORK with autoCommit off, firstexecute a connection declaration clause to generate a connection context class:

#sql context ctx;

Then invoke java.sql.Driver.GetConnection with the argumentjdbc:db2os390sqlj:NEWYORK:

Connection jdbccon=DriverManager.getConnection("jdbc:db2os390sqlj:NEWYORK");

Next, to set autoCommit off for the connection, invoke setAutoCommit with anargument false:

jdbccon.setAutoCommit(false);

Finally, invoke the constructor for class ctx using the JDBC connection as theargument:

ctx myconn=new ctx(jdbccon);

SQLJ uses the JDBC java.sql.Connection class to connect to data sources. Yourapplication can invoke any method in the java.sql.Connection class.

Using result set iterators to retrieve rows from a result table

In DB2 application programs that are written in traditional host languages, you use acursor to retrieve individual rows from the result table that is generated by a a SELECTstatement. The SQLJ equivalent of a cursor is a result set iterator. A result set iterator isa Java object that you use to retrieve rows from a result table. Unlike a cursor, a resultset iterator can be passed as a parameter to a method.

You define a result set iterator using an iterator declaration clause, which specifies a listof Java data types. Those data type declarations represent columns in the result tableand are referred to as columns of the result set iterator. Table 1 shows each SQLJ datatype that you can specify in a result set iterator declaration and the equivalent SQL datatype.

Table 1. Equivalent SQLJ and SQL data types

SQLJ data type SQL data type

java.lang.String CHAR, VARCHAR, LONGVARCHAR,GRAPHIC, VARGRAPHIC, LONGVARGRAPHIC

java.math.BigDecimal NUMERIC, INTEGER, DECIMAL, SMALLINT,FLOAT, REAL, DOUBLE

Boolean INTEGER, SMALLINT

int, Integer SMALLINT, INTEGER, DECIMAL, NUMERIC,FLOAT, DOUBLE

float, Float SMALLINT, INTEGER, DECIMAL, NUMERIC,FLOAT, DOUBLE

20 Application Programming Guide and Reference for Java™

Page 29: Application Programming Guide and Reference

Table 1. Equivalent SQLJ and SQL data types (continued)

SQLJ data type SQL data type

double, Double SMALLINT, INTEGER, DECIMAL, DECIMAL,NUMERIC, FLOAT, DOUBLE

byte[]1 CHAR, VARCHAR, LONGVARCHAR,GRAPHIC, VARGRAPHIC, LONGVARGRAPHIC

java.sql.Date2 DATE

java.sql.Time2 TIME

java.sql.Timestamp2 TIMESTAMP

Notes to Table 1 on page 20:

1. Because this data type is equivalent to a DB2 data type with a subtype of BIT,SQLJ performs no conversion for data of this type.

2. This class is part of the JDBC API.

The two types of result set iterators are positioned iterators and named iterators. Thetype of result set iterator that you choose depends on the way that you plan to use thatresult set iterator. The following sections explain how to use each type of iterator.

Using positioned iterators

For a positioned iterator, the columns of the result set iterator correspond to thecolumns of the result table, in left-to-right order. For example, if an iterator declarationclause has two data type declarations, the first data type declaration corresponds to thefirst column in the result table, and the second data type declaration corresponds to thesecond column in the result table. You declare positioned iterators to execute FETCHstatements.

For example, the following iterator declaration clause defines a positioned iteratornamed ByPos with two columns. The first column is of type String, and the secondcolumn is of type Date.

#sql public iterator ByPos(String,Date);

When SQLJ encounters an iterator declaration clause for a positioned iterator, itgenerates a positioned iterator class with the name that you specify in the iteratordeclaration clause. You can then declare an object of the positioned iterator class toretrieve rows from a result table.

For example, suppose that you want to retrieve rows from a result table that containsthe values of the LASTNAME and HIREDATE columns from the DB2 sample employee

Chapter 3. Writing SQLJ programs for DB2 for OS/390 21

Page 30: Application Programming Guide and Reference

table. Figure 3 shows how you can declare an iterator named ByPos and use an objectof the generated class ByPos to retrieve those rows.

Notes to Figure 3:

�1� This SQLJ clause executes the SELECT statement, constructs an iterator object thatcontains the result table for the SELECT statement, and assigns the iterator object tovariable positer.

�2� SQLJ checks that the types of the host variables in the INTO clause match thecorresponding types of the iterator columns.

�3� Method endFetch(), which is a method of the generated iterator class ByPos, returns avalue of true when all rows have been retrieved from the iterator.

Using named iterators

You can use named iterators to select rows from a result table using SQL statementsother than FETCH statements. When you declare a named iterator for a query, youspecify names for each of the iterator columns. Those names must match the names ofcolumns in the result table for the query. An iterator column name and a result tablecolumn name that differ only in case are considered to be matching names.

When SQLJ encounters a named iterator declaration, it generates a named iteratorclass with the same name that you use in the iterator declaration clause. In the namediterator class, SQLJ generates an accessor method for each column name in theiterator declaration clause. The accessor method name is the same name as thecolumn name in the iterator declaration clause. You use the accessor method to retrievedata from the corresponding column of the result table.

When you execute an SQL clause that has a named iterator, SQLJ matches the nameof each iterator column to the name of a column in the result table. The columns of theiterator do not need to be in the same order as the columns of the result table.

{#sql public iterator ByPos(String,Date);

// Declare positioned iterator class ByPosByPos positer; // Declare object of ByPos classString name = null;Date hrdate;

�1� #sql positer = { SELECT LASTNAME, HIREDATE FROM EMP };�2� #sql { FETCH :positer INTO :name, :hrdate };

// Retrieve the first row from the result table�3� while ( !positer.endFetch() )

{ System.out.println(name + " was hired in " +hrdate);

#sql { FETCH :positer INTO :name, :hrdate };// Retrieve the rest of the rows

}}

Figure 3. Retrieving rows using a positioned iterator

22 Application Programming Guide and Reference for Java™

Page 31: Application Programming Guide and Reference

The following iterator declaration clause defines the named iterator ByName, which hastwo columns. The first column of the iterator is named LastName and is of type String.The second column is named HireDate and is of type Date.

#sql public iterator ByName(String LastName, Date HireDate);

You use a named iterator in an SQLJ assignment clause. An assignment clauseassigns the result table from a SELECT statement to an instance of a named iteratorclass. For example:

#sql nameiter={SELECT LASTNAME, HIREDATE FROM EMP};

Figure 4 shows how you can use a named iterator to retrieve rows from a result tablethat contains the values of the LASTNAME and HIREDATE columns of the employeetable.

Notes to Figure 4:

�1� This SQLJ clause creates the named iterator class ByName, which has accessormethods LastName() and HireDate() that return the data from result table columnsLASTNAME and HIREDATE.

�2� This SQLJ clause executes the SELECT statement, constructs an iterator object thatcontains the result table for the SELECT statement, and assigns the iterator object tovariable nameiter.

�3� next(), which is a method of the generated class ByName, advances the iterator tosuccessive rows of the result set. next returns a value of true when a next row isavailable, and a value of false when all rows have been fetched from the iterator.

�4� SQLJ checks that the types of the host variables in the assignment clause match thetypes that are returned by the corresponding accessor methods.

The column names for named iterators must be valid Java identifiers. The columnnames must also match the column names in the result table from which the iteratorretrieves rows. If a SELECT statement that uses a named iterator selects data from

{�1� #sql public iterator ByName(String LastName, Date HireDate);

ByName namiter; // Declare object of ByName class�2� #sql nameiter={SELECT LASTNAME, HIREDATE FROM EMP};

String name;Date hrdate;// advances to next row

�3� while (namiter.next()){

�4� hrdate = namiter.HireDate();// Returns value of column named HIREDATE

name = namiter.LastName();// Returns value of column named LASTNAME

System.out.println(name + " was hired on " + hrdate);}

}

Figure 4. Retrieving rows using a named iterator

Chapter 3. Writing SQLJ programs for DB2 for OS/390 23

Page 32: Application Programming Guide and Reference

columns with names that are not valid Java identifiers, you need to use SQL ASclauses in the SELECT statement to give the columns of the result table acceptablenames.

For example, suppose you want to use a named iterator to retrieve the rows that arespecified by this SELECT statement:

SELECT PUBLIC FROM GOODTABLE

The iterator column name must match the column name of the result table, but youcannot specify an iterator column name of PUBLIC because PUBLIC is a reserved Javakeyword. You must therefore use an AS clause to rename PUBLIC to a valid Javaidentifier in the result table. For example:

SELECT PUBLIC AS IS_PUBLIC FROM GOODTABLE

You can then declare a named iterator with a column name that is a valid Java identifierand matches the column name of the result table:

#sql public iterator ByName(String IS_PUBLIC);ByName namiter;#sql nameiter={SELECT PUBLIC AS IS_PUBLIC FROM GOODTABLE};

Using iterators for positioned UPDATE and DELETE operations

Unlike SQL statements that retrieve data from a table, positioned UPDATE andDELETE operations require two Java source files. In one source file, you must declarethe iterator. In the declaration, you must use an SQLJ implements clause to implementthe sqlj.runtime.ForUpdate interface. You must also declare the iterator as public. Forexample, use the following SQL clause to declare iterator ByPos, which has stringcolumn EmpNo, for use in a positioned DELETE statement:

#sqlj public iterator DelByName implements sqlj.runtime.ForUpdate(String EmpNo);

You can then use the iterator in a different source file. To use the iterator:

1. Import the generated iterator class.

2. Declare an instance of the generated iterator class.

3. Assign the SELECT statement for the positioned UPDATE or DELETE to the iteratorinstance.

4. Execute positioned UPDATE or DELETE statements using the iterator.

After the iterator is created, any SQLJ source file that has addressability to the iteratorand imports the generated class can retrieve data and execute positioned UPDATE orDELETE statements using the iterator. The authorization ID under which a positionedUPDATE or DELETE statement executes is the authorization ID under which the DB2package that contains the UPDATE or DELETE executes.

For example, suppose that you declare iterator DelByName like this in file1.sqlj:

#sqlj public iterator DelByName implements sqlj.runtime.ForUpdate(String EmpNo);

24 Application Programming Guide and Reference for Java™

Page 33: Application Programming Guide and Reference

To use DelByName for a positioned DELETE in file2.sqlj, execute statements like thosein Figure 5.

Notes to Figure 5:

�1� This statement imports named iterator class DelByName, which was created by theiterator declaration clause for DelByName in file1.sqlj.

�2� This SQLJ clause executes the SELECT statement, constructs an iterator object thatcontains the result table for the SELECT statement, and assigns the iterator object tovariable deliter.

�3� This statement positions the iterator to the next row to be deleted.�4� This SQLJ clause performs the positioned DELETE.

Controlling the execution of SQL statements

You can use selected methods of the SQLJ ExecutionContext class to query andmodify the characteristics of SQL statements during execution. “Appendix. Selectedsqlj.runtime classes and interfaces” on page 57 describes those methods.

To execute ExecutionContext methods for an SQL statement, you must declare anexecution context and associate that execution context with the SQL statement.

To declare an execution context, invoke the constructor for ExecutionContext andassign the result to a variable of type ExecutionContext. For example:

ExecutionContext execCtx=new ExecutionContext();

To associate an execution context with an SQL statement, specify the name of theexecution context, enclosed in square brackets, at the beginning of the executionclause that contains the SQL statement. For example:

#sql [execCtx] {DELETE FROM EMP WHERE SALARY > 10000};

�1� import DelByName;{DelByName deliter; // Declare object of DelByName classString enum;

�2� #sql deliter = { SELECT EMPNO FROM EMPWHERE WORKDEPT='D11'};

while (deliter.next()){

�3� enum = deliter.EmpNo(); // Get value from result table�4� #sql { DELETE WHERE CURRENT OF :deliter };

// Delete row where cursor is positioned}

}

Figure 5. Deleting rows using a positioned iterator

Chapter 3. Writing SQLJ programs for DB2 for OS/390 25

Page 34: Application Programming Guide and Reference

You can associate a different execution context with each SQL statement. If you alsouse an explicit connection context for an SQL statement, specify the connectioncontext, followed by the execution context in the execution clause for the SQLstatement. For example:

#sql [connCtx, execCtx] {DELETE FROM EMP WHERE SALARY > 10000};

If you do not specify an execution context for an execution clause, SQLJ uses thedefault execution context.

After you associate an execution context with an SQL statement, you can executeExecutionContext methods for that SQL statement. For example, you can use methodgetUpdateCount to count the number of rows that are deleted by a DELETE statement:

#sql [connCtx, execCtx] {DELETE FROM EMP WHERE SALARY > 10000};System.out.println("Deleted " + execCtx.getUpdateCount() + " rows");

An SQLJ sample program

Figure 6 on page 27 contains an example of an SQLJ program that prints the namesand salaries of employees with salaries that exceed the average for the company. Theprogram uses the DB2 sample employee table.

26 Application Programming Guide and Reference for Java™

Page 35: Application Programming Guide and Reference

Notes to Figure 6:

�1� The first two statements import the JDBC and SQLJ packages that are used by SQLJ.�2� This connection declaration clause declares connection context HSctx, which will be

used to connect to location SANJOSE. When you prepare the application program,SQLJ generates a class named HSctx. You must therefore ensure that HSctx is a validJava class name that is unique within its scope.

�3� This iterator declaration clause declares named iterator HSByName, which will be usedto select rows from the employee table. When you prepare the application program,SQLJ generates a class named HSByName. You must therefore ensure thatHSByName is a valid Java class name that is unique within its scope.

�1� import sqlj.runtime.*;import java.sql.*;import java.math.*;

�2� #sql context HSctx;�3� #sql iterator HSByName(String LastName, BigDecimal Salary);

public class HighSalary{public static void main (String[] args) // Main entry pointthrows SQLException

{try {

�4� Class.forName("COM.ibm.db2os390.sqlj.jdbc.DB2SQLJDriver");}catch (ClassNotFoundException e) {

e.printStackTrace();}

�5� Connection HSjdbccon=DriverManager.getConnection("jdbc:db2os390sqlj:SANJOSE");

HSjdbccon.setAutoCommit(false);HSctx myconn=new HSctx(HSjdbccon);BigDecimal AvgSal;#sql [myconn] {SELECT AVG(SALARY) INTO :AvgSal FROM EMP};printSalary(AvgSal,myconn);

}static void printSalary(BigDecimal AvgSalary, HSctx hsconn)throws SQLException // Method to get high salaries

{�6� HSByName nameiter;�7� #sql [hsconn] nameiter =

{SELECT LASTNAME, SALARY FROM EMPWHERE SALARY >= :AvgSalaryORDER BY SALARY DESC};

�8� while (nameiter.next())�9� System.out.println( nameiter.LastName() + " " +

nameiter.Salary());�10� nameiter.close();

}}

Figure 6. SQLJ sample program

Chapter 3. Writing SQLJ programs for DB2 for OS/390 27

Page 36: Application Programming Guide and Reference

�4� The Class.ForName method loads the DB2 for OS/390 SQLJ JDBC driver and registers itwith the DriverManager.

�5� This statement and the two statements that follow it set up the connection to the datasource at location SANJOSE and set autoCommit for the connection to off. Executableclauses that specify the connection instance myconn will be executed at locationSANJOSE.

�6� This statement declares nameiter as an instance of the named iterator classHSByName.

�7� This assignment clause executes the SELECT statement, constructs an iterator objectthat contains the result table for the SELECT statement, and assigns the iterator objectto variable nameiter.

�8� next, which is a method of the generated class HSByName, advances the iterator tosuccessive rows of the result set. next returns a value of true when a next row isavailable and a value of false when all rows have been fetched from the iterator.

�9� Accessor methods nameiter.LastName and nameiter.Salary retrieve the values of theLASTNAME and SALARY column from the current row of the result table.

�10� close, which is a method of generated iterator class HSByName, closes the iterator tofree any database resources that the iterator holds.

28 Application Programming Guide and Reference for Java™

Page 37: Application Programming Guide and Reference

Chapter 4. Preparing and running SQLJ programs

DB2 for OS/390 SQLJ programs run in the OS/390 OpenEdition environment. Thischapter explains how to configure OpenEdition for SQLJ, prepare and run SQLJprograms, and diagnose SQLJ problems. For information on how to install SQLJ, see“Chapter 6. JDBC and SQLJ administration” on page 51. The following topics arediscussed:

v “Configuring OpenEdition for SQLJ”

v “Steps in the SQLJ program preparation process” on page 30

v “Running SQLJ programs” on page 36

v “Diagnosing SQLJ problems” on page 36

Configuring OpenEdition for SQLJ

After you install SQLJ, and before you prepare and run SQLJ programs, set thefollowing environmental variables:

STEPLIBModify STEPLIB to include the SDSNEXIT and SDSNLOAD data sets. For example:

export STEPLIB=DSN510.SDSNEXIT:DSN510.SDSNLOAD

LIBPATH and LD_LIBRARY_PATHSQLJ contains four dynamic load libraries:

v libdb2os390sqljjdbc.so

v libdb2sqljcustom.so

v libdb2os390sqljjdbc_g.so

v libdb2sqljcustom_g.so

Modify LIBPATH and LD_LIBRARY_PATH to include the directory that containsthese DLLs. If SQLJ and JDBC are installed in /usr/lpp/db2, modify LIBPATH andLD_LIBRARY_PATH, respectively, as follows:

export LIBPATH=/usr:/usr/lib:/usr/lpp/db2/db2510/lib

export LD_LIBRARY_PATH=/usr/lpp/db2/db2510/lib

CLASSPATHModify CLASSPATH to include one of the following class files:

db2sqljclasses.zipContains all of the classes necessary to prepare and run SQLJ programs.Assuming that SQLJ is installed in /usr/lpp/db2, modify CLASSPATH asfollows:

export CLASSPATH=/usr/lpp/db2/db2510/classes/db2sqljclasses.zip

db2sqljruntime.zipContains all of the classes necessary to run SQLJ programs. Specify this class

© Copyright IBM Corp. 1998 29

Page 38: Application Programming Guide and Reference

file only if you do not plan to prepare SQLJ programs on your system.Assuming that SQLJ is installed in /usr/lpp/db2, modify CLASSPATH asfollows:

export CLASSPATH=/usr/lpp/db2/db2510/classes/db2sqljruntime.zip

DB2SQLJDBRMLIBSpecifies the fully-qualified name of the MVS partitioned data set into whichDBRMs are placed. DBRMs are generated by the customization step of the SQLJprogram preparation process. For example:

export DB2SQLJDBRMLIB=USER.DBRMLIB.DATA

The default DBRM data set name is prefix.DBRMLIB.DATA, where prefix is thehigh-level qualifier that was specified in the TSO profile for the user. prefix isusually the user's TSO user ID.

See “Customizing a serialized profile” on page 34 for more information on serializedprofile customization.

DB2SQLJPLANNAMESpecifies the name of the plan that is associated with an SQLJ application. Theplan is created by the DB2 for OS/390 bind process. For example:

export DB2SQLJPLANNAME=SQLJPLAN

DB2SQLJSSIDSpecifies the name of the DB2 subsystem to which an SQLJ application connects.For example:

export DB2SQLJSSID=DSN

DB2SQLJATTACHTYPESpecifies the attachment facility that an SQLJ application program uses to connectto DB2. The value can be CAF or RRSAF. For example:

export DB2SQLJATTACHTYPE=RRSAF

You must set other environmental variables if you need to generate diagnostic traces.You should set those environmental variables only under the direction of your IBMservice representative. See “Collecting trace data” on page 36 for information ondiagnostic traces and environmental variables for those traces.

Steps in the SQLJ program preparation process

After you write an SQLJ application, you must generate an executable form of theapplication, which involves:

1. Translating the source code to produce modified Java source code and serializedprofiles

2. Customizing the serialized profiles to produce DBRMs

3. Binding the DBRMs into packages and binding the packages into a plan, or bindingthe DBRMs directly into a plan

30 Application Programming Guide and Reference for Java™

Page 39: Application Programming Guide and Reference

Figure 7 shows the steps of the program preparation process.

This section discusses each of those steps.

Figure 7. The SQLJ program preparation process

Chapter 4. Preparing and running SQLJ programs 31

Page 40: Application Programming Guide and Reference

Translating SQLJ source code

The first step in preparing an executable SQLJ program is to use the SQLJ translator togenerate a Java source program and one or more serialized profiles. Execute the sqljcommand from the OpenEdition command line to invoke the DB2 for OS/390 SQLJtranslator.

Syntax

ÊÊ sqlj-help -dir=directory -props=properties-file

Ê

Êin

-default-block-mode= inoutoutunknown

in-default-procedure-mode= inout

outunknown

Ê

Êall

-warn= noneverbosenonverboseportablenonportable

file-list ÊÍ

Parameter descriptions-help

Specifies that the SQLJ translator describes each of the options that the translatorsupports.

-dir= directorySpecifies the name of the directory into which SQLJ puts output from the translator.This output consists of Java source files and serialized profile files. The defaultdirectory is the current directory.

The translator uses the directory structure of the SQLJ source files when it puts thegenerated files in directories. For example, suppose that you want the translator toprocess two files:

v file1.sqlj, which is not in a Java package

v file2.sqlj, which is in Java package sqlj.test

Also suppose that you specify the parameter -dir=/src when you invoke thetranslator. Then the translator puts the serialized profiles and Java source file forfile1.sqlj in directory /src and puts the serialized profiles and Java source file forfile2.sqlj in directory /src/sqlj/test.

32 Application Programming Guide and Reference for Java™

Page 41: Application Programming Guide and Reference

-props= properties-fileSpecifies the name of a file from which the SQLJ translator is to obtain a list ofoptions.

-default-block-mode=in|inout|out|unknownSpecifies the mode that the SQLJ translator should use for a host variable whenthe translator cannot determine whether the host variable is used for input, output,or both. The default is in.

-default-procedure-mode=in|inout|out|unknownSpecifies the mode that the SQLJ translator should use for a stored procedureparameter when the translator cannot determine whether the parameter is used forinput, output, or both. The default is in.

-warn= warning-levelSpecifies the types of messages that the SQLJ translator is to return. Themeanings of the warning levels are:

all The translator displays all warnings and informational messages. This is thedefault.

noneThe translator displays no warnings or informational messages.

verboseThe translator displays informational messages about the semantic analysisprocess.

nonverboseThe translator displays no informational messages about the semantic analysisprocess.

portableThe translator displays warning messages about the portability of SQLJclauses.

nonportableThe translator displays no warning messages about the portability of SQLJclauses.

file-listSpecifies a list of SQLJ source files to be translated. This is a required parameter.All SQLJ source file names must have the extension .sqlj.

Output from the SQLJ translator

For each source file, program-name.sqlj, the SQLJ translator produces the followingfiles:

v The modified source program

The modified source file is named program-name.java.

v A serialized profile file for each connection context that is specified in the program

Chapter 4. Preparing and running SQLJ programs 33

Page 42: Application Programming Guide and Reference

A serialized profile file is named program-name_SJProfilen.ser, where n is 0 for thefirst serialized profile generated for the program, 1 for the second serialized profilegenerated, and so on.

You must run the SQLJ customizer on each serialized profile file to produce astandard DB2 for OS/390 DBRM. See “Customizing a serialized profile” forinformation on how to customize a serialized profile.

Compiling an SQLJ program

After you translate your SQLJ source file and receive a modified source file, use thejavac command to compile the modified source file. Compile the modified source file asyou would compile any other Java program.

Customizing a serialized profile

After you use the SQLJ translator to generate serialized profiles for an SQLJ program,customize each serialized profile to produce a standard DB2 for OS/390 DBRM and aserialized profile that is customized for DB2 for OS/390. To customize a serializedprofile, execute the db2profc on the OpenEdition command line.

Syntax

ÊÊ db2profc-help -version ISO

-date= USAEURJIS

ISO-time= USA

EURJIS

Ê

ÊALL

-sql= DB2

-pgmname=DBRM-member-name serialized-profile-name ÊÍ

Parameter descriptions-help

Specifies that the SQLJ customizer describes each of the options that thecustomizer supports.

-versionSpecifies that the SQLJ customizer returns the version of the SQLJ customizer.

-date=ISO|USA|EUR|JISSpecifies that date values that you retrieve from an SQL table should always be ina particular format, regardless of the format that is specified as the location default.For a description of these formats, see Chapter 3 of SQL Reference. The default isISO.

-time=ISO|USA|EUR|JISSpecifies that time values that you retrieve from an SQL table should always be in

34 Application Programming Guide and Reference for Java™

Page 43: Application Programming Guide and Reference

a particular format, regardless of the format that is specified as the location default.For a description of these formats, see Chapter 3 of SQL Reference. The default isISO.

-sql=ALL|DB2Indicates whether the source program contains SQL statements other than thosethat DB2 for OS/390 recognizes.

ALL, which is the default, indicates that the SQL statements in the program are notnecessarily for DB2 for OS/390. Use ALL for application programs whose SQLstatements must execute on a server other that DB2 for OS/390.

DB2 indicates that the SQLJ customizer should interpret SQL statements and checksyntax for use by DB2 for OS/390. Use DB2 when the application server is DB2 forOS/390.

-pgmname= DBRM-member-nameSpecifies the name for the DBRM that the SQLJ customizer generates. This namemust be 8 or fewer characters in length and must conform to the rules for namingmembers of MVS partitioned data sets.

serialized-profile-nameSpecifies the name of the serialized profile that is to be customized. Serializedprofiles are generated by the SQLJ translator and have names of the form

program-name_SJProfilen.ser

program-name is the name of the SQLJ source program, without the extension.sqlj. n is an integer between 0 and m-1, where m is the number of serializedprofiles that the SQLJ translator generated from the SQLJ source program.

Output from the SQLJ customizer

When the SQLJ customizer runs, it creates a DBRM and a modified serialized profile. Ifthe customizer runs successfully, it generates the following message:

Serialized Profile serialized-profile-name has been customized for DB2 for OS/390

Binding a plan for an SQLJ program

After you have customized the serialized profiles for your SQLJ application program,you must bind the DBRMs that are produced by the SQLJ customizer. You can bind theDBRMs directly into a plan or bind the DBRMs into packages and then bind thepackages into a plan. For information on binding packages and plans, see Chapter 2 ofCommand Reference.

Chapter 4. Preparing and running SQLJ programs 35

Page 44: Application Programming Guide and Reference

Running SQLJ programs

After you have set the environmental variables discussed in “Configuring OpenEditionfor SQLJ” on page 29 and prepared your program for execution, your program is readyto run.

To ensure that the program can find all the files that it needs:

v Put the serialized profiles for the program in the same directory as the class files forthe program.

v Include class files that are used by the program in the CLASSPATH.

To run your SQLJ program, execute the java command from the OS/390 OpenEditioncommand line:

java program-name

Diagnosing SQLJ problems

SQLJ programs can generate two types of errors:

v Recoverable errors

SQLJ reports recoverable SQL errors through the JDBC java.SQLException class.You can use methods getErrorCode and getSQLState to retrieve SQLCODEs andSQLSTATEs. See “Handling SQL errors and warnings” on page 17 for information onhow to write your application program to retrieve SQLCODEs and SQLSTATEs.

All SQLSTATEs except FFFFF are documented in Section 2 of Messages andCodes. FFFFF is a special SQLSTATE that indicates an internal error in SQLJ.

v Non-recoverable errors

These errors do not throw an SQLException, or the application cannot catch theexception.

To diagnose recoverable errors that generate SQLSTATE FFFFF or repeatable,non-recoverable errors, you can collect trace data and run three utilities that generateadditional diagnostic information. You should run the trace and diagnostic utilities onlyunder the direction of your IBM service representative.

Collecting trace data

Before you can collect SQLJ trace data, you must set one or more of the followingenvironmental variables:

PATHSpecifies the directories to search for application code. If the directory in which thetrace formatter program db2sqljtrace resides is not already in the search path, addthat directory. For example, if db2sqljtrace is in /usr/lpp/db2/db2510/bin, add/usr/lpp/db2/db2510/bin to the PATH environmental variable:

export PATH=/bin:/usr/bin:/usr/lpp/db2/db2510/bin

36 Application Programming Guide and Reference for Java™

Page 45: Application Programming Guide and Reference

DB2SQLJ_TRACE_FILENAMESpecifies the name of the trace file to which a DB2 SQLJ trace is written. Thisvariable is required for collecting trace data. For example:

export DB2SQLJ_TRACE_FILENAME=SYSADM.TRACE

DB2SQLJ_TRACE_BUFFERSIZE= yyyySpecifies the size of the trace buffer in virtual storage in kilobytes. That is, yyyy isyyyy KB. SQLJ rounds the number that you specify down to a multiple of 64 KB.The default is 512 KB. This is an optional variable. For example:

export DB2SQLJ_TRACE_BUFFERSIZE=1024

DB2SQLJ_TRACE_WRAP= nEnables or disables wrapping of the SQLJ trace. Values of n are:

1 Wrap the trace

0 Do not wrap the trace

This variable is optional. For example:

export DB2SQLJ_TRACE_WRAP=0

To format the trace data, execute the db2sqljtrace command. db2sqljtrace writes theformatted data to stdout. The format of db2sqljtrace is:

ÊÊ db2sqljtrace fmtflw

input-file-name ÊÍ

The meanings of the parameters are:

fmtSpecifies that the output trace file is to contain a record of each time a function isentered or exited before the failure occurs.

flw Specifies that the output trace file is to contain the function flow before the failureoccurs.

input-file-nameSpecifies the name of the file from which db2sqljtrace is to read the unformattedtrace data. This name is the name you specified for environmental variableDB2SQLJ_TRACE_FILENAME.

Running diagnosis utilities

If an SQLJ application program receives a recoverable, internal error (SQLSTATEFFFFF) or a repeatable, non-recoverable error, run diagnosis utilities profp, profdb, anddb2profp, which are provided with SQLJ, to obtain additional information about theerror.

Chapter 4. Preparing and running SQLJ programs 37

Page 46: Application Programming Guide and Reference

The profp utility captures information about each SQLJ clause in a serialized profile.The format of the profdb utility is:

ÊÊ profp serialized-profile-name ÊÍ

Run the profp utility on the serialized profile for the connection in which the erroroccurs. If an exception is thrown, a Java stack trace is generated. You can determinewhich serialized profile was in use when the exception was thrown from the stack trace.

The db2profp utility captures information about each SQLJ clause in a customizedserialized profile. A customized serialized profile is a serialized profile on which the DB2for OS/390 SQLJ customizer has been run. The format of the db2profp utility is:

ÊÊ db2profp customized-serialized-profile-name ÊÍ

Run the db2profp utility on the customized serialized profile for the connection in whichthe error occurs.

The profdb utility customizes serialized profiles so that SQLJ captures extra informationabout run-time calls. The syntax of the profdb utility is:

ÊÊ profdb · serialized-profile-name ÊÍ

Run the profdb utility on every serialized profile that is associated with the SQLJapplication program that received the internal error. After you run profdb, rerun theapplication program to gather the diagnostic information.

38 Application Programming Guide and Reference for Java™

Page 47: Application Programming Guide and Reference

Chapter 5. SQLJ statement reference

The SQL statements in your SQLJ program are in SQLJ clauses. The general syntax ofan SQLJ clause is:

ÊÊ #sql connection-declaration-clauseiterator-declaration-clauseexecutable-clause

; ÊÍ

This chapter describes each of the three clauses that can appear in an SQLJ clauseand the elements that you can include in each of those clauses. Elements that aresubcomponents of several other elements are discussed first.

For more information and examples of using the clauses described in this chapter, see“Chapter 3. Writing SQLJ programs for DB2 for OS/390” on page 15.

© Copyright IBM Corp. 1998 39

Page 48: Application Programming Guide and Reference

Common elements

This section describes the elements that are common to several SQLJ clauses.

host-expression

A host expression is a Java variable or expression that is referenced by SQLJ clausesin an SQLJ application program.

Syntax

ÊÊINOUTINOUT

:simple-variable:(complex-expression)

ÊÍ

DescriptionIN|OUT|INOUT

For a host expression that is used as a parameter in a stored procedure call,identifies whether the parameter provides data to the stored procedure (IN),retrieves data from the stored procedure (OUT), or does both (INOUT). This is anoptional parameter.

: Indicates that the variable or expression that follows is a host expression. Thecolon must immediately precede the variable or expression.

simple-variableSpecifies a Java unqualified identifier.

complex-expressionSpecifies a Java expression that results in a single value.

Usage notesv A complex expression must be enclosed in parentheses.

v ANSI/ISO rules govern where a host expression can appear in a static SQLstatement.

v The string __sJT_ is a reserved prefix for variable names that are generated bySQLJ. Do not begin the following types of names with __sJT_:

– Host expression names

– Java variable names that are declared in blocks that include executable SQLstatements

– Names of parameters for methods that contain executable SQL statements

– Names of fields in classes that contain executable SQL statements, or in classeswith subclasses or enclosed classes that contain executable SQL statements

v The string _SJ is a reserved suffix for resource files and classes that are generatedby SQLJ. Avoid using the string _SJ in class names and input source file names.

40 Application Programming Guide and Reference for Java™

Page 49: Application Programming Guide and Reference

implements-clause

The implements clause derives one or more classes from a Java interface.

Syntax

ÊÊ implements ·

,

interface-element ÊÍ

interface-element:

ÊÊ ·

,

sqlj.runtime.ForUpdate ( java-data-type java-ID )user-specified-interface-class

ÊÍ

Descriptioninterface-element

Specifies a user-defined Java interface, or the SQLJ interfacesqlj.runtime.ForUpdate.

You must implement sqlj.runtime.ForUpdate when you declare an iterator for apositioned UPDATE or positioned DELETE operation. The parameters ofsqlj.runtime.ForUpdate are the columns of the iterator that you use for thepositioned UPDATE or positioned DELETE operation. See “Using iterators forpositioned UPDATE and DELETE operations” on page 24 for information onperforming a positioned UPDATE or positioned DELETE operation in SQLJ.

Chapter 5. SQLJ statement reference 41

Page 50: Application Programming Guide and Reference

with-clause

The with clause specifies a set of one or more attributes for an iterator or a connectioncontext.

Syntax

ÊÊ with ·

,

with-element ÊÍ

with-element:

ÊÊ holdability= truefalse

returnability= truefalse

Java-ID=Java-constant-expression

ÊÍ

Descriptionholdability

Specifies whether an iterator keeps its position in a table after a COMMIT isexecuted. The value for holdability must be true or false.

returnabilitySpecifies whether an iterator can return result sets from a stored procedure call.The value for returnability must be true or false.

Java-IDSpecifies a Java variable that identifies a user-defined attribute of an iterator orconnection context. The value of Java-constant-expression is also user-defined.

Usage notesv The value on the left side of a with element must be unique within its with clause.

v For a connection declaration clause, only user-defined attributes(Java-ID=Java-constant-expression) can be specified in a with clause.

42 Application Programming Guide and Reference for Java™

Page 51: Application Programming Guide and Reference

connection-declaration-clause

The connection declaration clause declares a connection to a data source in an SQLJapplication program.

Syntax

ÊÊJava-modifiers

context Java-class-nameimplements-clause

Ê

Êwith-clause

ÊÍ

Java-modifiers:

ÊÊprivateprotectedpublic

finalstatictransientvolatile

ÊÍ

DescriptionJava-modifiers

Specifies modifiers that are valid for Java class declarations.

Java-class-nameSpecifies a valid Java identifier. During the program preparation process, SQLJgenerates a connection context class whose name is this identifier.

implements-clauseSee “implements-clause” on page 41 for a description of this clause. In aconnection declaration clause, the interface class to which the implements clauserefers must be a user-defined interface class.

with-clauseSee “with-clause” on page 42 for a description of this clause. In a connectiondeclaration clause, all attributes in a with clause must be user defined.

Usage notesv SQLJ generates a connection class declaration for each connection declaration

clause you specify. SQLJ data source connections are objects of those generatedconnection classes.

v You can specify a connection declaration clause anywhere that a Java classdefinition can appear in a Java program.

Chapter 5. SQLJ statement reference 43

Page 52: Application Programming Guide and Reference

iterator-declaration-clause

An iterator declaration clause declares a positioned iterator class or a named iteratorclass in an SQLJ application program. An iterator contains the result table from a query.SQLJ generates an iterator class for each iterator declaration clause you specify. Aniterator is an object of an iterator class.

An iterator declaration clause has a form for a positioned iterator and a form for anamed iterator. The two kinds of iterators are distinct and incompatible Java types thatare implemented with different interfaces. See “Using result set iterators to retrieve rowsfrom a result table” on page 20 for information on how to use each type of iterator.

Syntax

ÊÊJava-modifiers

iterator Java-class-nameimplements-clause

Ê

Êwith-clause

( positioned-iterator-column-declarations )named-iterator-column-declarations

ÊÍ

Java modifiers:

ÊÊprivateprotectedpublic

finalstatictransientvolatile

ÊÍ

positioned-iterator-column declarations:

ÊÊ ·

,

Java-data-type ÊÍ

named-iterator-column-declarations:

ÊÊ ·

,

Java-data-type Java-ID ÊÍ

44 Application Programming Guide and Reference for Java™

Page 53: Application Programming Guide and Reference

DescriptionJava-modifiers

Any modifiers that are valid for Java class declarations.

Java-class-nameAny valid Java identifier. During the program preparation process, SQLJ generatesan iterator class whose name is this identifier.

implements-clauseSee “implements-clause” on page 41 for a description of this clause. For an iteratordeclaration clause that declares an iterator for a positioned UPDATE or positionedDELETE operation, the implements clause must specify interfacesqlj.runtime.ForUpdate.

with-clauseSee “with-clause” on page 42 for a description of this clause.

positioned-iterator-column-declarationsSpecifies a list of Java data types, which are the data types of the columns in thepositioned iterator. The data types in the list must be separated by commas. Theorder of the data types in the positioned iterator declaration is the same as theorder of the columns in the result table. The data types of the columns in theiterator must be compatible with the data types of the columns in the result table.See Table 1 on page 20 for a list of compatible data types. A positioned iterator canbe used only for FETCH statements.

named-iterator-column-declarationsSpecifies a list of Java data types and Java identifiers, which are the data typesand names of the columns in the named iterator. Pairs of data types and namesmust be separated by commas. The name of a column in the iterator must match,except for case, the name of a column in the result table. The data types of thecolumns in the iterator must be compatible with the data types of the columns inthe result table. See Table 1 on page 20 for a list of compatible data types. Anamed iterator cannot be used for a FETCH statement.

Usage notesv An iterator declaration clause can appear anywhere in a Java program that a Java

class declaration can appear.

v When a named iterator declaration contains more than one pair of Java data typesand Java IDs, all Java IDs within the list must be unique.

Chapter 5. SQLJ statement reference 45

Page 54: Application Programming Guide and Reference

executable-clause

An executable clause contains an SQL statement or an assignment statement. Anassignment statement assigns the result of an SQL operation to a Java variable.

This section first describes the executable clause in general. The next three sectionsdescribe each of the components of an executable clause.

Syntax

ÊÊcontext-clause

statement-clauseassignment-clause

ÊÍ

Usage notesv An executable clause can appear anywhere in a Java program that a Java statement

can appear.

v SQLJ reports nonzero SQL codes from executable clauses through classjava.sql.SQLException.

If SQLJ raises a run-time exception during the execution of an executable clause, thevalue of any host expression of type OUT or INOUT is undefined.

context-clause

A context clause specifies a connection context or an execution context. You use aconnection context to connect to a data source. You use an execution context tomonitor and modify SQL statement execution. See “Connecting to a data source” onpage 18 for information on using a connection context. See “Controlling the execution ofSQL statements” on page 25 for information on using an execution context.

Syntax

ÊÊ [ connection-contextexecution-contextconnection-context , execution context

] ÊÍ

Descriptionconnection-context

Specifies a valid Java identifier that is declared earlier in the SQLJ program. Thatidentifier must be declared as an instance of the connection context class thatSQLJ generates for a connection declaration clause.

46 Application Programming Guide and Reference for Java™

Page 55: Application Programming Guide and Reference

execution-contextSpecifies a valid Java identifier that is declared earlier in the SQLJ program. Thatidentifier must be declared as an instance of the constructor for classsqlj.runtime.ExecutionContext.

Usage notesv If you do not specify a connection context in an executable clause, SQLJ connects to

the local DB2 subsystem.

v If you do not specify an execution context, SQLJ obtains the execution context fromthe connection context of the statement.

statement-clause

A statement clause contains an SQL statement. All SQL statements are described inChapter 6 of SQL Reference.

Syntax

ÊÊ { SQL-statement } ÊÍ

DescriptionSQL-statement

You can include the following SQL statements in a statement clause:

Table 2. Valid SQL statements in an SQLJ statement clauseALTER DATABASEALTER INDEXALTER STOGROUPALTER TABLEALTER TABLESPACECALLCOMMITCREATE ALIASCREATE DATABASECREATE GLOBAL TEMPORARY TABLECREATE INDEXCREATE STOGROUPCREATE SYNONYMCREATE TABLECREATE TABLESPACECREATE VIEWDELETE

Chapter 5. SQLJ statement reference 47

Page 56: Application Programming Guide and Reference

Table 2. Valid SQL statements in an SQLJ statement clause (continued)DROP ALIASDROP DATABASEDROP INDEXDROP PACKAGEDROP PROGRAMDROP STOGROUPDROP SYNONYMDROP TABLEDROP TABLESPACEDROP VIEWEXPLAINFETCHGRANTINSERTLOCK TABLERENAMEREVOKEROLLBACKSELECTSET CURRENT DEGREESET host-variableSET CURRENT PACKAGESETSET CURRENT RULESSET CURRENT SQLIDUPDATE

Usage notesv SQLJ supports both positioned and searched DELETE and UPDATE operations.

v For a FETCH statement, a positioned DELETE statement, or a positioned UPDATEstatement, you must use an iterator to obtain rows from a result table. See “Usingresult set iterators to retrieve rows from a result table” on page 20 for moreinformation on iterators.

assignment-clause

The assignment clause assigns the result table from a SELECT statement to an iterator.

Syntax

ÊÊ Java-ID= { subselect } ÊÍ

DescriptionJava-ID

Identifies an iterator that was declared previously as an instance of an iteratorclass.

48 Application Programming Guide and Reference for Java™

Page 57: Application Programming Guide and Reference

subselectGenerates a result table. The syntax of the subselect is defined in Chapter 5 ofSQL Reference.

Usage notesv The number and types of the columns in the result table of the subselect must match

the number and types of the variables in the expression on the left side of theassignment clause.

v You can put an assignment clause anywhere in a Java program that a Javaassignment statement can appear. However, you cannot put an assignment clausewhere a Java assignment expression can appear. For example, you cannot specifyan assignment clause in the control list of a for statement.

Chapter 5. SQLJ statement reference 49

Page 58: Application Programming Guide and Reference

50 Application Programming Guide and Reference for Java™

Page 59: Application Programming Guide and Reference

Chapter 6. JDBC and SQLJ administration

This chapter contains the following topics about the administration of JDBC and SQLJ:

v “Installing JDBC and SQLJ”

v “JDBC and SQLJ security model” on page 53

v “JDBC and SQLJ multiple context support” on page 54

Installing JDBC and SQLJ

The steps in this section describe the SMP/E jobs you need to edit and run to installDB2 JDBC and SQLJ. Customize these jobs to specify data set names for your DB2installation and SMP/E data sets. Refer to the header notes in each job and to Section2 of Installation Guide for details.

All steps, except for those noted differently, are for both JDBC and SQLJ installation.

Step 1: Copy and edit the SMP/E jobs

Use this sample JCL to invoke the MVS utility IEBCOPY to copy the SMP/E jobs toDASD.

Define the italicized variables in the JCL as follows:

tunitThe unit value matching the product tape or cartridge.

jcl-library-nameThe name of the data set where the sample jobs are to reside.

dasdvolThe volume serial of the DASD device where the data set is to reside.

//STEP1 EXEC PGM=IEBCOPY//SYSPRINT DD SYSOUT=A//IN DD DSN=IBM.JDB5512.F2,UNIT=tunit,VOL=SER=DB5512,// LABEL=(3,SL),DISP=(OLD,KEEP)//OUT DD DSNAME=jcl-library-name,// DISP=(NEW,CATLG,DELETE),// VOL=SER=dasdvol,UNIT=dunit,// DCB=*.STEP1.IN,SPACE=(TRK,(1,1,2))//SYSUT3 DD UNIT=SYSDA,SPACE=(CYL,(1,1))//SYSIN DD *COPY INDD=IN,OUTDD=OUT

/*

Figure 8. Sample JCL to copy SMP/E jobs to DASD

© Copyright IBM Corp. 1998 51

Page 60: Application Programming Guide and Reference

dunitThe DASD unit type of the volume.

Step 2: Run the allocate job: DSNTJJAE

DSNTJJAE allocates the necessary MVS data sets and creates DDDEF entries intarget and distribution libraries.

Optional Step: Allocate HFS data set

If you prefer to install DB2 JDBC and SQLJ in a separate HFS data set, rather than theroot file system, use the following sample JCL to allocate an HFS data set:

Define the italicized variables in the JCL as follows:

db2hlqThe high-level data set qualifier that is used for this DB2.

dasdvolThe volume serial of the DASD device where the data set is to reside.

dunitThe DASD unit type of the volume.

storclasAn appropriate SMS storage class that is defined on your system.

Step 3: Create Hierarchical File System (HFS) structure

Use the TSO MKDIR command to create the DB2 installation directory in your HFS:

TSO MKDIR '/usr/lpp/db2' MODE(7 5 5)

The spaces in ’MODE(7 5 5)’ are important.

Optional: If you installed DB2 JDBC and SQLJ into a separate HFS data set, mountthe new HFS data set created on the DB2 JDBC and SQLJ HFS install mountpoint. Thefollowing command must be on one line:

//ALLOCHFS EXEC PGM=IEFBR14//SYSPRINT DD SYSOUT=*//*//* NOTE: THIS HFS DATA SET MUST BE DFSMS MANAGED//*//SDSNHFS DD DSN=db2hlq.SDSNHFS,// DISP=(NEW,CATLG,DELETE),// VOL=SER=dasdvol,UNIT=dunit,// SPACE=(CYL,(5,1,1))// DSNTYPE=HFS,STORCLAS=storclas//*

Figure 9. Sample JCL to allocate an HFS data set

52 Application Programming Guide and Reference for Java™

Page 61: Application Programming Guide and Reference

TSO MOUNT FILESYSTEM('db2hlq.SDSNHFS') MOUNTPOINT('/usr/lpp/db2') TYPE(HFS)

db2hlq is the high-level data set qualifier that is used in the preceding optional step.

You can now run the sample REXX exec, DSNISMKD, to create the HFS structure. Torun DSNISMKD, you must have OpenEdition root authority.

Step 4: Run the receive Job: DSNTJJRC

DSNTJJRC invokes SMP/E to receive the FMIDs for DB2 JDBC and SQLJ into theSMP/E control data sets.

Step 5: Run the apply job: DSNTJJAP

DSNTJJAP invokes SMP/E to apply the FMIDs for DB2 JDBC and SQLJ to the DB2target libraries.

Step 6: Run the accept job: DSNTJJAC

DSNTJJAC invokes SMP/E to accept the FMIDs for DB2 JDBC and SQLJ into the DB2distribution libraries.

Step 7: Run the SQLJ allocate jobs

Follow the instructions in APAR PQ18939 to create DDDEF entries in target librariesand allocate the HFS directories for SQLJ installation.

Step 8: Install SQLJ modules

Receive, apply, and accept APAR PQ19814 to install the modules that constitute DB2for OS/390 SQLJ.

JDBC and SQLJ security model

This section describes the JDBC and SQLJ security model. It explains howauthorization IDs are determined and the use of attachment facilities.

How are authorization IDs established?

An important difference between JDBC and SQLJ on OS/390 and on other operatingsystems is the manner in which the database authorization ID is determined.

On operating systems other than OS/390, the user ID and password that are passed asparameters on the java.sql.Connection constructor determine the authorization ID thatthe database uses.

Chapter 6. JDBC and SQLJ administration 53

Page 62: Application Programming Guide and Reference

In contrast, the security environment created by the OS/390 Security Server (RACFACEE) determines the DB2 for OS/390 authorization ID that is used for a thread. Ifnon-null values are specified for user ID or password on the java.sql.Connectionconstructor, the SQLJ JDBC driver COM.ibm.db2os390sqlj.jdbc.DB2SQLJDriver throws ajava.sql.SQLException.

It is important to note that DB2 does not create the security environment. Theapplication or server that provides the point of entry into the OS/390 system (i.e. TSOlogon, Telnet logon, Web Server, etc.) typically creates the security environment.

DB2 attachment types

The security environment (the RACF ACEE) that DB2 uses to establish the DB2authorization IDs is dependent on which DB2 attachment type you use. Both JDBC andSQLJ use a DB2 attachment facility, either the call attachment facility (CAF) or the RRSattachment facility (RRSAF), to communicate with DB2.

Both attachment types support multithreading, that is, multiple, concurrent threads(TCBs) that execute within a single process (address space). In a multithreadingenvironment, each process and thread can have its own unique security environment.The DB2 attachment facility that you select determines which security environment DB2uses to verify the DB2 authorization IDs.

Using the call attachment facility

The DB2 call attachment facility (CAF) supports multithreading, single authorization IDapplications. As such, the DB2 CAF always uses the process (address space) levelsecurity environment, even if a thread level security environment is present. Therefore,all threads that run within a single process are execute using the same DB2authorization ID.

Using the RRS attachment facility

In contrast to the DB2 call attachment facility, the DB2 RRS attachment facility (RRSAF)supports multithreading, and applications can run under multiple authorization IDs. Ifyou use the RRSAF, DB2 uses a task-level security environment, if present, to establishthe DB2 authorization IDs.

JDBC and SQLJ multiple context support

A context consists of the application’s logical connection to the data source and theassociated internal DB2 connection information that lets the application direct itsoperations to a data source. For JDBC or SQLJ applications, a context is equivalent toa DB2 thread.

54 Application Programming Guide and Reference for Java™

Page 63: Application Programming Guide and Reference

Connecting when multiple context support is not enabled

A context is always established when a Java thread creates its firstjava.sql.Connection object. If support for multiple contexts is not enabled, thensubsequent java.sql.Connection objects created by a Java thread share that singlecontext. Although multiple connections can share a single context, only one connectioncan have an active transaction at any time. If there is an active transaction on aconnection, a COMMIT or ROLLBACK must be issued before the Java thread can useor create another connection object.

Without multiple context support:

v There can be one or more Java threads, any of which can issue JDBC or SQLJcalls.

v All java.sql.Connection objects are explicitly closed by the application rather than bycleanup.

v Multiple, concurrent java.sql.Connection objects can be created by a single Javathread, provided that the application does not attempt to create or use a differentconnection object on the Java thread if the current connection is not on a transactionboundary.

Connecting when multiple context support is enabled

With multiple context support enabled, each java.sql.Connection object results in thecreation of a unique context (DB2 thread) for that connection. Under this model, asingle Java thread (TCB) can have multiple, concurrent connections, each with its ownindependent transaction. The DB2 JDBC and SQLJ multiple context support requires:

v Use of the DB2 RRSAF attachment facility

v OS/390 Unauthorized Context Services, available in OS/390 Version 2, Release 5 orhigher

With multiple context support:

v There can be one or more Java threads, any of which can issue JDBC or SQLJcalls.

v The Java threads can create multiple java.sql.Connection objects (and derivedobjects), each of which:

– Can exist concurrently with other java.sql.Connection objects.

– Has its own transaction scope that is independent from all otherjava.sql.Connections.

– Does not need to be on a transaction boundary for a Java thread to create or usedifferent connections.

v The java.sql.Connection objects can be shared between Java threads. However,the actions of one Java thread on a given connection object are also visible to all ofthe Java threads using that connection. Also, the JDBC/SQLJ application isresponsible for ensuring proper serialization when sharing connection objectsbetween threads.

Chapter 6. JDBC and SQLJ administration 55

Page 64: Application Programming Guide and Reference

v Although it is recommended that all java.sql.Statement and java.sql.Connectionobjects be explicitly closed by the application, it is not required.

Connection sharing

Connection sharing occurs whenever a Java thread (TCB) attempts to use ajava.sql.Connection object, or any object derived from a connection, that the Javathread did not create.

One application of connection sharing is for cleanup of connection objects. Under someimplementations of the Java Virtual Machine (JVM) on OS/390, cleanup of connectionobjects can be performed under a separate thread, rather than the Java thread thatcreated the object.

Connection sharing is supported only in a multiple context environment.

56 Application Programming Guide and Reference for Java™

Page 65: Application Programming Guide and Reference

Appendix. Selected sqlj.runtime classes and interfaces

The sqlj.runtime package defines the run-time classes and interfaces that SQLJ uses.This appendix describes:

v Each class of sqlj.runtime that contains methods that you can invoke in your SQLJapplication programs

v Each of the interfaces that you might need to implement in your SQLJ applicationprograms

sqlj.runtime.ExecutionContext class

The sqlj.runtime.ExecutionContext class is defined for execution contexts. You canuse an execution context to control the execution of SQL statements. After you declarean execution context and create an instance of that execution context, you can use thefollowing methods.

getMaxFieldSizeFormat:

public int getMaxFieldSize()

Returns the maximum number of bytes that are returned for any character columnin queries that use the given execution context. A value of 0 means that themaximum number of bytes is unlimited.

getMaxRowsFormat:

public int getMaxRows()

Returns the maximum number of rows that are returned for any query that uses thegiven execution context. A value of 0 means that the maximum number of rows isunlimited.

getUpdateCountFormat:

public abstract int getUpdateCount() throws SQLException

Returns the number of rows that were updated by the last SQL operation that wasexecuted using this context.

getWarningsFormat:

public SQLWarning getWarnings()

Returns the first warning that was reported by the last SQL operation that wasexecuted using this context. Use this method to retrieve positive SQLCODEs.

© Copyright IBM Corp. 1998 57

Page 66: Application Programming Guide and Reference

setMaxFieldSizeFormat:

public void setMaxFieldSize(int max)

Specifies the maximum number of bytes that are returned for any character columnin queries that use the given execution context. The default is 0, which means thatthe maximum number of bytes is unlimited.

setMaxRowsFormat:

public void setMaxRows(int max)

Specifies the maximum number of rows that are returned for any query that usesthe given execution context. The default is 0, which means that the maximumnumber of rows returned is unlimited.

sqlj.runtime.ForUpdate interface

Implement the sqlj.runtime.ForUpdate interface for positioned UPDATE or DELETEoperations. You implement sqlj.runtime.ForUpdate in an SQLJ iterator declarationclause. For positioned UPDATE and DELETE operations, you must declare an iteratorin one source file and use the iterator in a different source file. See “Using iterators forpositioned UPDATE and DELETE operations” on page 24 for more information.

sqlj.runtime.NamedIterator interface

sqlj.runtime.NamedIterator is an interface that SQLJ implements when you declare anamed iterator. When you declare an instance of a named iterator, SQLJ creates anaccessor method for each column in the expected result table. An accessor methodreturns the data from its column of the result table. The name of an accessor methodmatches the name of the corresponding column in the named iterator.

In addition to the accessor methods, SQLJ generates the following methods that youcan invoke in your SQLJ application.

closeFormat:

public abstract void close() throws SQLException

Releases database resources that the iterator uses.

isClosedFormat:

public abstract boolean isClosed() throws SQLException

Returns a value of true if the close method has been invoked.

58 Application Programming Guide and Reference for Java™

Page 67: Application Programming Guide and Reference

nextFormat:

public abstract boolean next() throws SQLException

Advances the iterator to the next row. Before an instance of the next method isinvoked for the first time, the iterator is positioned before the first row of the resulttable. next returns a value of true when a next row is available and false when allrows have been retrieved.

sqlj.runtime.PositionedIterator interface

sqlj.runtime.PositionedIterator is an interface that SQLJ implements when youdeclare a positioned iterator. After you declare and create an instance of a positionediterator, you can use the following method.

endFetchFormat:

public abstract boolean endFetch() throws SQLException

Returns a value of true if the iterator is not positioned on a row.

Appendix. Selected sqlj.runtime classes and interfaces 59

Page 68: Application Programming Guide and Reference

60 Application Programming Guide and Reference for Java™

Page 69: Application Programming Guide and Reference

Notices

This information was developed for products and services offered in the U.S.A. IBMmay not offer the products, services, or features discussed in this document in othercountries. Consult your local IBM representative for information on the products andservices currently available in your area. Any reference to an IBM product, program, orservice is not intended to state or imply that only that IBM product, program, or servicemay be used. Any functionally equivalent product, program, or service that does notinfringe any IBM intellectual property right may be used instead. However, it is theuser’s responsibility to evaluate and verify the operation of any non-IBM product,program, or service.

IBM may have patents or pending patent applications covering subject matter describedin this document. The furnishing of this document does not give you any license tothese patents. You can send license inquiries, in writing, to:

IBM Director of LicensingIBM CorporationNorth Castle DriveArmonk, NY 10504-1785U.S.A.

For license inquiries regarding double-byte (DBCS) information, contact the IBMIntellectual Property Department in your country or send inquiries, in writing, to:

IBM World Trade Asia CorporationLicensing2-31 Roppongi 3-chome, Minato-kuTokyo 106, Japan

The following paragraph does not apply to the United Kingdom or any othercountry where such provisions are inconsistent with local law: INTERNATIONALBUSINESS MACHINES CORPORATION PROVIDES THIS PUBLICATION “AS IS”WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING,BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF NON-INFRINGEMENT,MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Some states donot allow disclaimer of express or implied warranties in certain transactions, therefore,this statement may not apply to you.

This information could include technical inaccuracies or typographical errors. Changesare periodically made to the information herein; these changes will be incorporated innew editions of the publication. IBM may make improvements and/or changes in theproduct(s) and/or the program(s) described in this publication at any time without notice.

Any references in this publication to non-IBM Web sites are provided for convenienceonly and do not in any manner serve as an endorsement of those Web sites. Thematerials at those Web sites are not part of the materials for this IBM product and useof those Web sites is at your own risk.

© Copyright IBM Corp. 1998 61

Page 70: Application Programming Guide and Reference

Licensees of this program who wish to have information about it for the purpose ofenabling: (i) the exchange of information between independently created programs andother programs (including this one) and (ii) the mutual use of the information which hasbeen exchanged, should contact:

IBM CorporationJ74/G4555 Bailey AvenueP.O. Box 49023San Jose, CA 95161-9023U.S.A.

Such information may be available, subject to appropriate terms and conditions,including in some cases, payment of a fee.

The licensed program described in this information and all licensed material availablefor it are provided by IBM under terms of the IBM Customer Agreement, IBMInternational Program License Agreement, or any equivalent agreement between us.

Information concerning non-IBM products was obtained from the suppliers of thoseproducts, their published announcements or other publicly available sources. IBM hasnot tested those products and cannot confirm the accuracy of performance,compatibility or any other claims related to non-IBM products. Questions on thecapabilities of non-IBM products should be addressed to the suppliers of thoseproducts.

COPYRIGHT LICENSE:

This information contains sample application programs in source language, whichillustrates programming techniques on various operating platforms. You may copy,modify, and distribute these sample programs in any form without payment to IBM, forthe purposes of developing, using, marketing or distributing application programsconforming to the application programming interface for the operating platform for whichthe sample programs are written. These examples have not been thoroughly testedunder all conditions. IBM, therefore, cannot guarantee or imply reliability, serviceability,or function of these programs.

Programming interface information

This book is intended to help the customer write applications that use Java to accessIBM DB2 for OS/390 servers. This book documents General-use Programming Interfaceand Associated Guidance Information provided by DATABASE 2 for OS/390 (DB2 forOS/390).

General-use programming interfaces allow the customer to write programs that obtainthe services of DB2 for OS/390.

62 Application Programming Guide and Reference for Java™

Page 71: Application Programming Guide and Reference

Trademarks

The following terms are trademarks of the International Business Machines Corporationin the United States, or other countries, or both:

AIXBookManagerC++/MVSCICSCICS/ESACICS/MVSDATABASE 2DB2DB2/2DB2/6000DFSMSDFSMShsmDistributed Relational

Database ArchitectureDRDA

IBMIMSIMS/ESALanguage EnvironmentMVSMVS/ESAOS/2OS/390OS/400Parallel SysplexQMFRACFSQL/DSVTAM

Other company, product, and service names may be trademarks or service marks ofothers.

Java and all Java-based trademarks and logos are trademarks or registeredTrademarks of Sun Microsystems, Inc. in the United States and other countries.

UNIX is a registered trademark in the United States and other countries licensedexclusively through X/Open Company Limited.

Notices 63

Page 72: Application Programming Guide and Reference

64 Application Programming Guide and Reference for Java™

Page 73: Application Programming Guide and Reference

Glossary

The following terms and abbreviations are definedas they are used in the DB2 library. If you do notfind the term you are looking for, refer to the indexor to Dictionary of Computing.

A

abend. Abnormal end of task.

abend reason code. A 4-byte hexadecimal codethat uniquely identifies a problem with DB2. Acomplete list of DB2 abend reason codes andtheir explanations is contained in Messages andCodes

abnormal end of task (abend). Termination of atask, a job, or a subsystem because of an errorcondition that cannot be resolved during executionby recovery facilities.

access path. The path used to get to dataspecified in SQL statements. An access path caninvolve an index or a sequential search.

address space. A range of virtual storage pagesidentified by a number (ASID) and a collection ofsegment and page tables which map the virtualpages to real pages of the computer’s memory.

address space connection. The result ofconnecting an allied address space to DB2. Eachaddress space containing a task connected toDB2 has exactly one address space connection,even though more than one task control block(TCB) can be present. See allied address spaceand task control block.

alias. An alternate name that can be used inSQL statements to refer to a table or view in thesame or a remote DB2 subsystem.

allied address space. An area of storageexternal to DB2 that is connected to DB2 and istherefore capable of requesting DB2 services.

allied thread. A thread originating at the localDB2 subsystem that may access data at a remoteDB2 subsystem.

ambiguous cursor. A database cursor that isnot defined with either the clauses FOR FETCHONLY or FOR UPDATE OF, is not defined on aread-only result table, is not the target of aWHERE CURRENT clause on an SQL UPDATEor DELETE statement, and is in a plan or packagethat contains SQL statements PREPARE orEXECUTE IMMEDIATE.

API. Application programming interface.

application. A program or set of programs thatperform a task; for example, a payroll application.

application plan. The control structure producedduring the bind process and used by DB2 toprocess SQL statements encountered duringstatement execution.

application process. The unit to whichresources and locks are allocated. An applicationprocess involves the execution of one or moreprograms.

application program interface (API). Afunctional interface supplied by the operatingsystem or by a separately orderable licensedprogram that allows an application program writtenin a high-level language to use specific data orfunctions of the operating system or licensedprogram.

application requester (AR). See requester.

application server. See server.

AR. application requester. See requester.

AS. Application server. See server.

ASCII. An encoding scheme used to representstrings in many environments, typically on PCsand workstations. Contrast with EBCDIC.

attribute. A characteristic of an entity. Forexample, in database design, the phone numberof an employee is one of that employee’sattributes.

© Copyright IBM Corp. 1998 65

Page 74: Application Programming Guide and Reference

authorization ID. A string that can be verified forconnection to DB2 and to which a set of privilegesare allowed. It can represent an individual, anorganizational group, or a function, but DB2 doesnot determine this representation.

B

base table. A table created by the SQL CREATETABLE statement that is used to hold persistentdata. Contrast with result table and temporarytable.

binary integer. A basic data type that can befurther classified as small integer or large integer.

bind. The process by which the output from theDB2 precompiler is converted to a usable controlstructure called a package or an application plan.During the process, access paths to the data areselected and some authorization checking isperformed.

automatic bind . (More correctly automaticrebind). A process by which SQL statementsare bound automatically (without a user issuinga BIND command) when an applicationprocess begins execution and the boundapplication plan or package it requires is notvalid.

dynamic bind . A process by which SQLstatements are bound as they are entered.

incremental bind . A process by which SQLstatements are bound during the execution ofan application process, because they could notbe bound during the bind process, andVALIDATE(RUN) was specified.

static bind . A process by which SQLstatements are bound after they have beenprecompiled. All static SQL statements areprepared for execution at the same time.Contrast with dynamic bind.

bit data. Data that is not associated with acoded character set.

BMP. Batch Message Processing (IMS).

built-in function. Scalar function or columnfunction.

C

CAF. Call attachment facility.

call attachment facility (CAF). A DB2attachment facility for application programsrunning in TSO or MVS batch. The CAF is analternative to the DSN command processor andallows greater control over the executionenvironment.

catalog. In DB2, a collection of tables thatcontains descriptions of objects such as tables,views, and indexes.

catalog table. Any table in the DB2 catalog.

CCSID. Coded character set identifier.

CDB. See communications database.

CDRA. Character data representationarchitecture.

central processor (CP). The part of thecomputer that contains the sequencing andprocessing facilities for instruction execution, initialprogram load, and other machine operations.

character data representation architecture(CDRA). An architecture used to achieveconsistent representation, processing, andinterchange of string data.

character set. A defined set of characters.

character string. A sequence of bytesrepresenting bit data, single-byte characters, or amixture of single and double-byte characters.

check clause. An extension to the SQLCREATE TABLE and SQL ALTER TABLEstatements that specifies a table check constraint.

check constraint. See table check constraint.

check integrity. The condition that exists wheneach row in a table conforms to the table checkconstraints defined on that table. Maintainingcheck integrity requires enforcing table checkconstraints on operations that add or change data.

66 Application Programming Guide and Reference for Java™

Page 75: Application Programming Guide and Reference

check pending. A state of a table space orpartition that prevents its use by some utilities andsome SQL statements, because it can containrows that violate referential constraints, tablecheck constraints, or both.

CICS. Represents (in this publication) CICS/MVSand CICS/ESA.

CICS/MVS: Customer Information ControlSystem/Multiple Virtual Storage.

CICS/ESA: Customer Information ControlSystem/Enterprise Systems Architecture.

CICS attachment facility. A DB2 subcomponentthat uses the MVS Subsystem Interface (SSI) andcross storage linkage to process requests fromCICS to DB2 and to coordinate resourcecommitment.

clause. In SQL, a distinct part of a statement,such as a SELECT clause or a WHERE clause.

client. See requester.

CLIST. Command list. A language for performingTSO tasks.

clustering index. An index that determines howrows are physically ordered in a table space.

coded character set. A set of unambiguousrules that establish a character set and theone-to-one relationships between the charactersof the set and their coded representations.

coded character set identifier (CCSID). A16-bit number that uniquely identifies a codedrepresentation of graphic characters. It designatesan encoding scheme identifier and one or morepairs consisting of a character set identifier and anassociated code page identifier.

code page. A set of assignments of charactersto code points.

code point. In CDRA, a unique bit pattern thatrepresents a character in a code page.

collection. A group of packages that have thesame qualifier.

column function. An SQL operation that derivesits result from a collection of values across one ormore rows. Contrast with scalar function.

command. A DB2 operator command or a DSNsubcommand. Distinct from an SQL statement.

commit. The operation that ends a unit of workby releasing locks so that the database changesmade by that unit of work can be perceived byother processes.

commit point. A point in time when data isconsidered consistent.

committed phase. The second phase of themulti-site update process that requests allparticipants to commit the effects of the logicalunit of work.

communications database (CDB). A set oftables in the DB2 catalog that are used toestablish conversations with remote databasemanagement systems.

comparison operator. A token (such as =, >, <)used to specify a relationship between two values.

composite key. An ordered set of key columnsof the same table.

concurrency. The shared use of resources bymore than one application process at the sametime.

connection. The existence of a communicationpath between two partner LUs that allowsinformation to be exchanged (for example, twoDB2s connected and communicating by way of aconversation).

connection context. In SQLJ, a Java object thatrepresents a connection to a data source.

connection declaration clause. In SQLJ, astatement that declares a connection to a datasource.

consistency token. A timestamp used togenerate the version identifier for an application.See also version.

Glossary 67

Page 76: Application Programming Guide and Reference

constant. A language element that specifies anunchanging value. Constants are classified asstring constants or numeric constants. Contrastwith variable.

constraint. A rule that limits the values that canbe inserted, deleted, or updated in a table. Seereferential constraint, uniqueness constraint, andtable check constraint.

correlated subquery. A subquery (part of aWHERE or HAVING clause) applied to a row orgroup of rows of a table or view named in anouter sub-SELECT statement.

correlation name. An identifier that designates atable, a view, or individual rows of a table or viewwithin a single SQL statement. It can be defined inany FROM clause or in the first clause of anUPDATE or DELETE statement.

CP. See central processor (CP).

current data. Data within a host structure that iscurrent with (identical to) the data within the basetable.

cursor stability (CS). The isolation level thatprovides maximum concurrency without the abilityto read uncommitted data. With cursor stability, aunit of work holds locks only on its uncommittedchanges and on the current row of each of itscursors.

D

DASD. Direct access storage device.

database. A collection of tables, or a collectionof table spaces and index spaces.

database access thread. A thread accessingdata at the local subsystem on behalf of a remotesubsystem.

database administrator (DBA). An individualresponsible for the design, development,operation, safeguarding, maintenance, and use ofa database.

database descriptor (DBD). An internalrepresentation of DB2 database definition which

reflects the data definition found in the DB2catalog. The objects defined in a databasedescriptor are table spaces, tables, indexes, indexspaces, and relationships.

database management system (DBMS). Asoftware system that controls the creation,organization, and modification of a database andaccess to the data stored within it.

database request module (DBRM). A data setmember created by the DB2 precompiler thatcontains information about SQL statements.DBRMs are used in the bind process.

DATABASE 2 Interactive (DB2I). The DB2facility that provides for the execution of SQLstatements, DB2 (operator) commands,programmer commands, and utility invocation.

data currency. The state in which data retrievedinto a host variable in your program is a copy ofdata in the base table.

data definition name (DD name). The name ofa data definition (DD) statement that correspondsto a data control block containing the same name.

Data Language/I (DL/I). The IMS datamanipulation language; a common high-levelinterface between a user application and IMS.

data partition. A VSAM data set that iscontained within a partitioned table space.

data sharing. The ability of two or more DB2subsystems to directly access and change asingle set of data.

data sharing group. A collection of one or moreDB2 subsystems that directly access and changethe same data while maintaining data integrity.

data sharing member. A DB2 subsystemassigned by XCF services to a data sharinggroup.

data type. An attribute of columns, literals, hostvariables, special registers, and the results offunctions and expressions.

68 Application Programming Guide and Reference for Java™

Page 77: Application Programming Guide and Reference

date. A three-part value that designates a day,month, and year.

date duration. A decimal integer that representsa number of years, months, and days.

datetime value. A value of the data type DATE,TIME, or TIMESTAMP.

DBA. Database administrator.

DBCS. Double-byte character set.

DBD. Database descriptor.

DBMS. Database management system.

DBRM. Database request module.

DB2 catalog. Tables maintained by DB2 thatcontain descriptions of DB2 objects such astables, views, and indexes.

DB2 command. An instruction to the DB2subsystem allowing a user to start or stop DB2, todisplay information on current users, to start orstop databases, to display information on thestatus of databases, and so on.

DB2I. DATABASE 2 Interactive.

DB2 private protocol access. A method ofaccessing distributed data by which you can directa query to another DB2 system by using an aliasor a three-part name to identify the DB2subsystems at which the statements are executed.Contrast with DRDA access.

DB2 private protocol connection. A DB2private connection of the application process. Seealso private connection.

DCLGEN. Declarations generator.

DDF. Distributed data facility.

DD name. Data definition name.

deadlock. Unresolvable contention for the use ofa resource such as a table or an index.

declarations generator (DCLGEN). Asubcomponent of DB2 that generates SQL table

declarations and COBOL, C, or PL/I data structuredeclarations that conform to the table. Thedeclarations are generated from DB2 systemcatalog information. DCLGEN is also a DSNsubcommand.

default value. A predetermined value, attribute,or option that is assumed when no other isexplicitly specified.

degree of parallelism. The number ofconcurrently executed operations that are initiatedto process a query.

delimited identifier. A sequence of charactersenclosed within quotation marks ("). The sequencemust consist of a letter followed by zero or morecharacters, each of which is a letter, digit, or theunderscore character (_).

delimiter token. A string constant, a delimitedidentifier, an operator symbol, or any of the specialcharacters shown in syntax diagrams.

dependent. An object (row, table, or table space)is a dependent if it has at least one parent. Theobject is also said to be a dependent (row, table,or table space) of its parent. See parent row,parent table, parent table space.

direct access storage device (DASD). A devicein which access time is independent of thelocation of the data.

distributed data facility (DDF). A set of DB2components through which DB2 communicateswith another RDBMS.

distributed relational database architecture(DRDA). A connection protocol for distributedrelational database processing that is used byIBM’s relational database products. DRDAincludes protocols for communication between anapplication and a remote relational databasemanagement system, and for communicationbetween relational database managementsystems.

DL/I. Data Language/I. The IMS datamanipulation language; a common high-levelinterface between a user application and IMS.

Glossary 69

Page 78: Application Programming Guide and Reference

double-byte character set (DBCS). A set ofcharacters used by national languages such asJapanese and Chinese that have more symbolsthan can be represented by a single byte. Eachcharacter is two bytes in length, and thereforerequires special hardware to be displayed orprinted.

drain. To acquire a locked resource by quiescingaccess to that object.

drain lock. A lock on a claim class whichprevents a claim from occurring.

DRDA. Distributed relational databasearchitecture.

DRDA access. A method of accessingdistributed data by which you can explicitlyconnect to another location, using an SQLstatement, to execute packages that have beenpreviously bound at that location. The SQLCONNECT statement is used to identifyapplication servers, and SQL statements areexecuted using packages that were previouslybound at those servers. Contrast with DB2 privateprotocol access.

DSN. (1) The default DB2 subsystem name. (2)The name of the TSO command processor ofDB2. (3) The first three characters of DB2 moduleand macro names.

duration. A number that represents an interval oftime. See date duration, labeled duration, and timeduration.

dynamic SQL. SQL statements that areprepared and executed within an applicationprogram while the program is executing. Indynamic SQL, the SQL source is contained in hostlanguage variables rather than being coded intothe application program. The SQL statement canchange several times during the applicationprogram’s execution.

E

EBCDIC. Extended binary coded decimalinterchange code. An encoding scheme used to

represent character data in the MVS, VM, VSE,and OS/400 environments. Contrast with ASCII.

embedded SQL. SQL statements coded withinan application program. See static SQL.

equi-join. A join operation in which thejoin-condition has the form expression =expression.

escape character. The symbol used to enclosean SQL delimited identifier. The escape characteris the quotation mark (″), except in COBOLapplications, where the symbol (either a quotationmark or an apostrophe) can be assigned by theuser.

EUR. IBM European Standards.

execution context. In SQLJ, a Java object thatcan be used to control the execution of SQLstatements.

explicit hierarchical locking. Locking used tomake the parent/child relationship betweenresources known to IRLM. This is done to avoidglobal locking overhead when no inter-DB2interest exists on a resource.

expression. An operand or a collection ofoperators and operands that yields a single value.

F

false global lock contention. A contentionindication from the coupling facility when multiplelock names are hashed to the same indicator andwhen there is no real contention.

fixed-length string. A character or graphic stringwhose length is specified and cannot be changed.Contrast with varying-length string.

foreign key. A key that is specified in thedefinition of a referential constraint. Because ofthe foreign key, the table is a dependent table.The key must have the same number of columns,with the same descriptions, as the primary key ofthe parent table.

70 Application Programming Guide and Reference for Java™

Page 79: Application Programming Guide and Reference

full outer join. The result of a join operation thatincludes the matched rows of both tables beingjoined and preserves the unmatched rows of bothtables. See also join.

function. A scalar function or column function.Same as built-in function.

G

global lock. A lock that provides both intra-DB2concurrency control and inter-DB2 concurrencycontrol, that is, the scope of the lock is across allthe DB2s of a data sharing group.

global lock contention. Conflicts on lockingrequests between different DB2 members of adata sharing group regarding attempts to serializeshared resources.

graphic string. A sequence of DBCS characters.

gross lock. The shared, update, or exclusivemode locks on a table, partition, or table space.

group name. The MVS XCF identifier for a datasharing group.

group restart. A restart of at least one memberof a data sharing group after either locks or theshared communications area have been lost.

H

help panel. A screen of information presentingtutorial text to assist a user at the terminal.

host expression. A Java variable or expressionthat is referenced by SQL clauses in an SQLJapplication program.

host identifier. A name declared in the hostprogram.

host language. A programming language inwhich you can embed SQL statements.

host program. An application program written ina host language that contains embedded SQLstatements.

host structure. In an application program, astructure referenced by embedded SQLstatements.

host variable. In an application program, anapplication variable referenced by embedded SQLstatements.

I

IFP. IMS Fast Path.

IMS. Information Management System.

IMS attachment facility. A DB2 subcomponentthat uses MVS Subsystem Interface (SSI)protocols and cross-memory linkage to processrequests from IMS to DB2 and to coordinateresource commitment.

index. A set of pointers that are logically orderedby the values of a key. Indexes can provide fasteraccess to data and can enforce uniqueness onthe rows in a table.

index key. The set of columns in a table used todetermine the order of index entries.

index partition. A VSAM data set that iscontained within a partitioned index space.

index space. A page set used to store theentries of one index.

indicator variable. A variable used to representthe null value in an application program. If thevalue for the selected column is null, a negativevalue is placed in the indicator variable.

indoubt. A status of a unit of recovery. If DB2fails after it has finished its phase 1 commitprocessing and before it has started phase 2, onlythe commit coordinator knows if this unit ofrecovery is to be committed or rolled back. Atemergency restart, if DB2 does not have theinformation needed to make this decision, its unitof recovery is indoubt until DB2 obtains thisinformation from the coordinator.

indoubt resolution. The process of resolving thestatus of an indoubt logical unit of work to eitherthe committed or the rollback state.

Glossary 71

Page 80: Application Programming Guide and Reference

inner join. The result of a join operation thatincludes only the matched rows of both tablesbeing joined. See also join.

Interactive System Productivity Facility(ISPF). An IBM licensed program that providesinteractive dialog services.

internal resource lock manager (IRLM). AnMVS subsystem used by DB2 to controlcommunication and database locking.

inter-DB2 R/W interest. A property of data in atable space, index, or partition that has beenopened by more than one member of a datasharing group and that has been opened forwriting by at least one of those members.

IRLM. internal resource lock manager.

ISO. International Standards Organization.

isolation level. The degree to which a unit ofwork is isolated from the updating operations ofother units of work. See also cursor stability,repeatable read, uncommitted read, and readstability.

ISPF/PDF. Interactive System ProductivityFacility/Program Development Facility.

iterator. In SQLJ, an object that contains theresult set of a query. An iterator is equivalent to acursor in other host languages.

iterator declaration clause. In SQLJ, astatement that generates an iterator declarationclass. An iterator is an object of an iteratordeclaration class.

J

JCL. Job control language.

JIS. Japanese Industrial Standard.

join. A relational operation that allows retrieval ofdata from two or more tables based on matchingcolumn values. See also full outer join, inner join,left outer join, outer join, right outer join, equi-join.

K

KB. Kilobyte (1024 bytes).

key. A column or an ordered collection ofcolumns identified in the description of a table,index, or referential constraint.

L

labeled duration. A number that represents aduration of years, months, days, hours, minutes,seconds, or microseconds.

left outer join. The result of a join operation thatincludes the matched rows of both tables beingjoined, and preserves the unmatched rows of thefirst table. See also join.

link-edit. To create a loadable computer programusing a linkage editor.

L-lock. See logical lock.

load module. A program unit that is suitable forloading into main storage for execution. Theoutput of a linkage editor.

local. Refers to any object maintained by thelocal DB2 subsystem. A local table, for example, isa table maintained by the local DB2 subsystem.Contrast with remote.

local lock. A lock that provides intra-DB2concurrency control, but does not provideinter-DB2 concurrency control; that is, its scope isa single DB2.

local subsystem. The unique RDBMS to whichthe user or application program is directlyconnected (in the case of DB2, by one of the DB2attachment facilities).

location name. The name by which DB2 refersto a particular DB2 subsystem in a network ofsubsystems. Contrast with LU name.

lock. A means of controlling concurrent events oraccess to data. DB2 locking is performed by theIRLM.

72 Application Programming Guide and Reference for Java™

Page 81: Application Programming Guide and Reference

lock duration. The interval over which a DB2lock is held.

lock escalation. The promotion of a lock from arow or page lock to a table space lock becausethe number of page locks concurrently held on agiven resource exceeds a preset limit.

locking. The process by which the integrity ofdata is ensured. Locking prevents concurrentusers from accessing inconsistent data.

lock mode. A representation for the type ofaccess concurrently running programs can have toa resource held by a DB2 lock.

lock object. The resource that is controlled by aDB2 lock.

lock parent. For explicit hierarchical locking, alock held on a resource that has child locks thatare lower in the hierarchy; usually the table spaceor partition intent locks are the parent locks.

lock promotion. The process of changing thesize or mode of a DB2 lock to a higher level.

lock size. The amount of data controlled by aDB2 lock on table data; the value can be a row, apage, a table, or a table space.

logical index partition. The set of all keys thatreference the same data partition.

logical lock. The lock type used by transactionsto control intra- and inter-DB2 data concurrencybetween transactions.

logical unit. An access point through which anapplication program accesses the SNA network inorder to communicate with another applicationprogram.

logical unit of work (LUW). In IMS, theprocessing that program performs betweensynchronization points.

LU name. From logical unit name, the name bywhich VTAM refers to a node in a network.Contrast with location name.

LUW. Logical unit of work.

M

mixed data string. A character string that cancontain both single-byte and double-bytecharacters.

modify locks. An L-lock or P-lock that has beenspecifically requested as having the MODIFYattribute. A list of these active locks are kept at alltimes in the coupling facilitylock structure. If therequesting DB2 fails, that DB2’s modify locks areconverted to retained locks.

MPP. Message processing program (IMS).

multi-site update. Distributed relationaldatabase processing in which data is updated inmore than one location within a single unit ofwork.

MVS. Multiple Virtual Storage.

MVS/ESA. Multiple Virtual Storage/EnterpriseSystems Architecture.

MVS/XA. Multiple Virtual Storage/ExtendedArchitecture.

N

negotiable lock. A lock whose mode can bedowngraded, by agreement among contendingusers, to be compatible to all. A physical lock is anexample of a negotiable lock.

nonpartitioned index. Any index that is not thepartitioned index of a partitioned table space.

NUL. In C, a single character that denotes theend of the string.

null. A special value that indicates the absenceof information.

NUL-terminated host variable. A varying-lengthhost variable in which the end of the data isindicated by the presence of a NUL terminator.

NUL terminator. In C, the value that indicatesthe end of a string. For character strings, the NULterminator is X'00'.

Glossary 73

Page 82: Application Programming Guide and Reference

O

ordinary identifier. An uppercase letter followedby zero or more characters, each of which is anuppercase letter, a digit, or the underscorecharacter. An ordinary identifier must not be areserved word.

ordinary token. A numeric constant, an ordinaryidentifier, a host identifier, or a keyword.

outer join. The result of a join operation thatincludes the matched rows of both tables beingjoined and preserves some or all of theunmatched rows of the tables being joined. Seealso join.

P

package. Also application package. An objectcontaining a set of SQL statements that havebeen bound statically and that are available forprocessing.

page. A unit of storage within a table space (4KBor 32KB) or index space (4KB). In a table space,a page contains one or more rows of a table.

page set. A table space or index spaceconsisting of pages that are either 4KB or 32KB insize. Each page set is made from a collection ofVSAM data sets.

parent row. A row whose primary key value isthe foreign key value of a dependent row.

parent table. A table whose primary key isreferenced by the foreign key of a dependenttable.

parent table space. A table space that containsa parent table. A table space containing adependent of that table is a dependent tablespace.

partitioned page set. A partitioned table spaceor an index space. Header pages, space mappages, data pages, and index pages referencedata only within the scope of the partition.

partitioned table space. A table spacesubdivided into parts (based upon index keyrange), each of which may be processed byutilities independently.

partner logical unit. An access point in the SNAnetwork that is connected to the local DB2 by wayof a VTAM conversation.

PCT. Program control table (CICS).

piece. A data set of a nonpartitioned page set.

physical consistency. The state of a page thatis not in a partially changed state.

physical lock contention. Conflicting states ofthe requesters for a physical lock. See negotiablelock.

physical lock (P-lock). A lock type used only bydata sharing that is acquired by DB2 to provideconsistency of data cached in different DB2subsystems.

plan. See application plan.

plan allocation. The process of allocating DB2resources to a plan in preparation to execute it.

plan member. The bound copy of a DBRMidentified in the member clause.

plan name. The name of an application plan.

P-lock. See physical lock.

point of consistency. A time when allrecoverable data an application accesses isconsistent with other data. Synonymous with syncpoint or commit point.

precision. In SQL, the total number of digits in adecimal number (called the size in the Clanguage). In the C language, the number of digitsto the right of the decimal point (called the scale inSQL). The DB2 library uses the SQL definitions.

precompilation. A processing of applicationprograms containing SQL statements that takesplace before compilation. SQL statements arereplaced with statements that are recognized bythe host language compiler. Output from this

74 Application Programming Guide and Reference for Java™

Page 83: Application Programming Guide and Reference

precompilation includes source code that can besubmitted to the compiler and the databaserequest module (DBRM) that is input to the bindprocess.

predicate. An element of a search condition thatexpresses or implies a comparison operation.

prepared SQL statement. A named object thatis the executable form of an SQL statement thathas been processed by the PREPARE statement.

primary index. An index that enforces theuniqueness of a primary key.

primary key. A unique, nonnull key that is part ofthe definition of a table. A table cannot be definedas a parent unless it has a unique key or primarykey.

private connection. A communicationsconnection that is specific to DB2.

Q

QMF. Query Management Facility.

R

RACF. OS/VS2 MVS Resource Access ControlFacility.

RCT. Resource control table (CICS attachmentfacility).

RDB. See relational database.

RDBMS. Relational database managementsystem.

RDBNAM. See relational database name.

read stability (RS). An isolation level that issimilar to repeatable read but does not completelyisolate an application process from all otherconcurrently executing application processes.Under level RS, an application that issues thesame query more than once might read additionalrows, known as phantom rows, that were insertedand committed by a concurrently executingapplication process.

rebind. To create a new application plan for anapplication program that has been boundpreviously. If, for example, you have added anindex for a table accessed by your application,you must rebind the application in order to takeadvantage of that index.

record. The storage representation of a row orother data.

recovery. The process of rebuilding databasesafter a system failure.

referential constraint. The requirement thatnonnull values of a designated foreign key arevalid only if they equal values of the primary keyof a designated table.

referential integrity. The condition that existswhen all intended references from data in onecolumn of a table to data in another column of thesame or a different table are valid. Maintainingreferential integrity requires enforcing referentialconstraints on all LOAD, RECOVER, INSERT,UPDATE, and DELETE operations.

relational database. A database that can beperceived as a set of tables and manipulated inaccordance with the relational model of data.

relational database management system(RDBMS). A relational database manager thatoperates consistently across supported IBMsystems.

relational database name (RDBNAM). A uniqueidentifier for an RDBMS within a network. In DB2,this must be the value in the LOCATION columnof table SYSIBM.LOCATIONS in the CDB. DB2publications refer to the name of another RDBMSas a LOCATION value or a location name.

remote. Refers to any object maintained by aremote DB2 subsystem; that is, by a DB2subsystem other than the local one. A remoteview, for instance, is a view maintained by aremote DB2 subsystem. Contrast with local.

remote subsystem. Any RDBMS, except thelocal subsystem, with which the user or applicationcan communicate. The subsystem need not be

Glossary 75

Page 84: Application Programming Guide and Reference

remote in any physical sense, and may evenoperate on the same processor under the sameMVS system.

repeatable read (RR). The isolation level thatprovides maximum protection from other executingapplication programs. When an applicationprogram executes with repeatable read protection,rows referenced by the program cannot bechanged by other programs until the programreaches a commit point.

request commit. The vote submitted to theprepare phase if the participant has modified dataand is prepared to commit or roll back.

requester. Also application requester (AR). Thesource of a request to a remote RDBMS, thesystem that requests the data.

resource control table (RCT). A construct of theCICS attachment facility, created by site-providedmacro parameters, that defines authorization andaccess attributes for transactions or transactiongroups.

resource limit facility (RLF). A portion of DB2code that prevents dynamic manipulative SQLstatements from exceeding specified time limits.

result set. The set of rows returned to a clientapplication by a stored procedure.

result table. The set of rows specified by aSELECT statement.

retained lock. A MODIFY lock that was held bya DB2 when that DB2 failed. The lock is retainedin the coupling facility lock structure across a DB2failure.

right outer join. The result of a join operationthat includes the matched rows of both tablesbeing joined and preserves the unmatched rows ofthe second join operand. See also join.

RLF. Resource limit facility.

rollback. The process of restoring data changedby SQL statements to the state at its last commitpoint. All locks are freed. Contrast with commit.

row. The horizontal component of a table. A rowconsists of a sequence of values, one for eachcolumn of the table.

RRSAF. Recoverable Resource ManagerServices attachment facility. A DB2 subcomponentthat uses OS/390 Transaction Management andRecoverable Resource Manager Services tocoordinate resource commitment between DB2and all other resource managers that also useOS/390 RRS in an OS/390 system.

S

scalar function. An SQL operation thatproduces a single value from another value and isexpressed as a function name followed by a list ofarguments enclosed in parentheses. See alsocolumn function.

scale. In SQL, the number of digits to the right ofthe decimal point (called the precision in the Clanguage). The DB2 library uses the SQLdefinition.

search condition. A criterion for selecting rowsfrom a table. A search condition consists of one ormore predicates.

sequential data set. A non-DB2 data set whoserecords are organized on the basis of theirsuccessive physical positions, such as onmagnetic tape. Several of the DB2 databaseutilities require sequential data sets.

serialized profile. A Java object that containsSQL statements and descriptions of hostvariables. A serialized profile is produced by theSQLJ translator. The SQLJ translator produces aserialized profile for each connection context.

server. Also application server (AS). The targetfor a request from a remote RDBMS, the RDBMSthat provides the data.

shared lock. A lock that prevents concurrentlyexecuting application processes from changingdata, but not from reading data.

76 Application Programming Guide and Reference for Java™

Page 85: Application Programming Guide and Reference

shift-in character. A special control character(X'0F') used in EBCDIC systems to denote thatthe following bytes represent SBCS characters.See shift-out character.

shift-out character. A special control character(X'0E') used in EBCDIC systems to denote thatthe following bytes, up to the next shift-in controlcharacter, represent DBCS characters.

single-precision floating point number. A32-bit approximate representation of a realnumber.

size. In the C language, the total number ofdigits in a decimal number (called the precision inSQL). The DB2 library uses the SQL definition.

source program. A set of host languagestatements and SQL statements that is processedby an SQL precompiler.

space. A sequence of one or more blankcharacters.

SPUFI. SQL Processor Using File Input. A facilityof the TSO attachment subcomponent thatenables the DB2I user to execute SQL statementswithout embedding them in an applicationprogram.

SQL. Structured Query Language.

SQL authorization ID (SQL ID). Theauthorization ID that is used for checking dynamicSQL statements in some situations.

SQL Communication Area (SQLCA). Astructure used to provide an application programwith information about the execution of its SQLstatements.

SQL Descriptor Area (SQLDA). A structure thatdescribes input variables, output variables, or thecolumns of a result table.

SQL escape character. The symbol used toenclose an SQL delimited identifier. This symbol isthe quotation mark (″). See escape character.

SQL ID. SQL authorization ID.

SQL return code. Either SQLCODE orSQLSTATE.

SQLCA. SQL communication area.

SQLDA. SQL descriptor area.

SQL/DS. SQL/Data System. Also known asDB2/VSE & VM.

SQLJ. An interface for including embedded SQLin a Java application program.

static SQL. SQL statements, embedded within aprogram, that are prepared during the programpreparation process (before the program isexecuted). After being prepared, the SQLstatement does not change (although values ofhost variables specified by the statement mightchange).

storage group. A named set of DASD volumeson which DB2 data can be stored.

stored procedure. A user-written applicationprogram, that can be invoked through the use ofthe SQL CALL statement.

string. See character string or graphic string.

Structured Query Language (SQL). Astandardized language for defining andmanipulating data in a relational database.

subquery. A SELECT statement within theWHERE or HAVING clause of another SQLstatement; a nested SQL statement.

subselect. That form of a query that does notinclude ORDER BY clause, UPDATE clause, orUNION operators.

substitution character. A unique character thatis substituted during character conversion for anycharacters in the source program that do not havea match in the target coding representation.

subsystem. A distinct instance of a RDBMS.

sync point. See commit point.

Glossary 77

Page 86: Application Programming Guide and Reference
Page 87: Application Programming Guide and Reference

variable. A data element that specifies a valuethat can be changed. A COBOL elementary dataitem is an example of a variable. Contrast withconstant.

varying-length string. A character or graphicstring whose length varies within set limits.Contrast with fixed-length string.

version. A member of a set of similar programs,DBRMs, or packages.

A version of a program is the source codeproduced by precompiling the program. Theprogram version is identified by the programname and a timestamp (consistency token).

A version of a DBRM is the DBRM producedby precompiling a program. The DBRM versionis identified by the same program name andtimestamp as a corresponding programversion.

A version of a package is the result ofbinding a DBRM within a particular databasesystem. The package version is identified bythe same program name and consistencytoken as the DBRM.

view. An alternative representation of data fromone or more tables. A view can include all or someof the columns contained in tables on which it isdefined.

Virtual Telecommunications Access Method(VTAM). An IBM licensed program that controlscommunication and the flow of data in an SNAnetwork.

VSAM. Virtual storage access method.

VTAM. MVS Virtual telecommunication accessmethod.

Glossary 79

Page 88: Application Programming Guide and Reference

80 Application Programming Guide and Reference for Java™

Page 89: Application Programming Guide and Reference

Bibliography

DB2 for OS/390 Version 5

v Administration Guide, SC26-8957

v Application Programming and SQL Guide,SC26-8958

v Call Level Interface Guide and Reference,SC26-8959

v Command Reference, SC26-8960

v Data Sharing: Planning and Administration,SC26-8961

v Data Sharing Quick Reference Card,SX26-3841

v Diagnosis Guide and Reference, LY27-9659

v Diagnostic Quick Reference Card, LY27-9660

v Installation Guide, GC26-8970

v Licensed Program Specifications, GC26-8969

v Messages and Codes, GC26-8979

v Reference for Remote DRDA Requesters andServers, SC26-8964

v Reference Summary, SX26-3842

v Release Guide, SC26-8965

v SQL Reference, SC26-8966

v Utility Guide and Reference, SC26-8967

v What's New?, GC26-8971

v Program Directory

DB2 PM for OS/390 Version 5

v Batch User’s Guide, SC26-8991

v Command Reference, SC26-8987

v General Information, GC26-8982

v Getting Started on the Workstation, SC26-8989

v Master Index, SC26-8984

v Messages Manual, SC26-8988

v Online Monitor User’s Guide, SC26-8990

v Report Reference Volume 1, SC26-8985

v Report Reference Volume 2, SC26-8986

v Program Directory

Ada/370

v IBM Ada/370 Language Reference, SC09-1297

v IBM Ada/370 Programmer's Guide, SC09-1414

v IBM Ada/370 SQL Module Processor for DB2Database Manager User's Guide, SC09-1450

APL2

v APL2 Programming Guide, SH21-1072

v APL2 Programming: Language Reference,SH21-1061

v APL2 Programming: Using Structured QueryLanguage (SQL), SH21-1057

AS/400

v DB2 for OS/400 SQL Programming, SC41-4611

v DB2 for OS/400 SQL Reference, SC41-4612

BASIC

v IBM BASIC/MVS Language Reference,GC26-4026

v IBM BASIC/MVS Programming Guide,SC26-4027

C/370

v IBM SAA AD/Cycle C/370 Programming Guide,SC09-1356

v IBM SAA AD/Cycle C/370 Programming Guidefor Language Environment/370, SC09-1840

v IBM SAA AD/Cycle C/370 User's Guide,SC09-1763

v SAA CPI C Reference, SC09-1308

Character Data Representation Architecture

v Character Data Representation ArchitectureOverview, GC09-2207

v Character Data Representation ArchitectureReference, SC09-2190

CICS/ESA

v CICS/ESA Application Programming Guide,SC33-1169

v CICS/ESA Application Programming Reference,SC33-1170

© Copyright IBM Corp. 1998 81

Page 90: Application Programming Guide and Reference

v CICS/ESA CICS - RACF Security Guide,SC33-1185

v CICS/ESA CICS-Supplied Transactions,SC33-1168

v CICS/ESA Customization Guide, SC33-1165

v CICS/ESA Data Areas, LY33-6083

v CICS/ESA Installation Guide, SC33-1163

v CICS/ESA Intercommunication Guide,SC33-1181

v CICS/ESA Messages and Codes, SC33-1177

v CICS/ESA Operations and Utilities Guide,SC33-1167

v CICS/ESA Performance Guide, SC33-1183

v CICS/ESA Problem Determination Guide,SC33-1176

v CICS/ESA Resource Definition Guide,SC33-1166

v CICS/ESA System Definition Guide, SC33-1164

v CICS/ESA System Programming Reference,GC33-1171

CICS/MVS

v CICS/MVS Application Programming Primer,SC33-0139

v CICS/MVS Application Programmer'sReference, SC33-0512

v CICS/MVS Facilities and Planning Guide,SC33-0504

v CICS/MVS Installation Guide, SC33-0506

v CICS/MVS Operations Guide, SC33-0510

v CICS/MVS Problem Determination Guide,SC33-0516

v CICS/MVS Resource Definition (Macro),SC33-0509

v CICS/MVS Resource Definition (Online),SC33-0508

IBM C/C++ for MVS/ESA

v IBM C/C++ for MVS/ESA Library Reference,SC09-1995

v IBM C/C++ for MVS/ESA Programming Guide,SC09-1994

IBM COBOL for MVS & VM

v IBM COBOL for MVS & VM LanguageReference, SC26-4769

v IBM COBOL for MVS & VM ProgrammingGuide, SC26-4767

Conversion Guides

v DBMS Conversion Guide: DATACOM/DB toDB2, GH20-7564

v DBMS Conversion Guide: IDMS to DB2,GH20-7562

v DBMS Conversion Guide: Model 204 to DB2 orSQL/DS, GH20-7565

v DBMS Conversion Guide: VSAM to DB2,GH20-7566

v IMS-DB and DB2 Migration and CoexistenceGuide, GH21-1083

Cooperative Development Environment

v CoOperative Development Environment/370:Debug Tool, SC09-1623

DATABASE 2 for Common Servers

v DATABASE 2 Administration Guide for commonservers, S20H-4580

v DATABASE 2 Application Programming Guidefor common servers, S20H-4643

v DATABASE 2 Software Developer's Kit for AIX:Building Your Applications, S20H-4780

v DATABASE 2 Software Developer's Kit forOS/2: Building Your Applications, S20H-4787

v DATABASE 2 SQL Reference for commonservers, S20H-4665

v DATABASE 2 Call Level Interface Guide andReference for common servers, S20H-4644

Data Extract (DXT)

v Data Extract Version 2: General Information,GC26-4666

v Data Extract Version 2: Planning andAdministration Guide, SC26-4631

DataPropagator NonRelational

v DataPropagator NonRelational MVS/ESAAdministration Guide, SH19-5036

82 Application Programming Guide and Reference for Java™

Page 91: Application Programming Guide and Reference

v DataPropagator NonRelational MVS/ESAReference, SH19-5039

DataPropagator Relational

v DataPropagator Relational User's Guide,SC26-3399

v IBM An Introduction to DataPropagatorRelational, GC26-3398

Data Facility Data Set Services

v Data Facility Data Set Services: User's Guideand Reference, SC26-4125

Database Design

v DB2 Database Design and ImplementationUsing DB2, SH24-6101

v DB2 Design and Development Guide, GabrielleWiorkowski and David Kull, Addison Wesley

v Handbook of Relational Database Design, C.Fleming and B Von Halle, Addison Wesley

v Principles of Database Systems, Jeffrey D.Ullman, Computer Science Press

DataHub

v IBM DataHub General Information, GC26-4874

DB2 Universal Database

v DB2 Universal Database Administration Guide,S10J-8157

v DB2 Universal Database API Reference,S10J-8167

v DB2 Universal Database Building Applicationsfor UNIX Environments, S10J-8161

v DB2 Universal Database Building Applicationsfor Windows and OS/2 Environments,S10J-8160

v DB2 Universal Database CLI Guide andReference, S10J-8159

v DB2 Universal Database SQL Reference,S10J-8165

Device Support Facilities

v Device Support Facilities User's Guide andReference, GC35-0033

DFSMS/MVS

v DFSMS/MVS: Access Method Services for theIntegrated Catalog, SC26-4906

v DFSMS/MVS: Access Method Services forVSAM Catalogs, SC26-4905

v DFSMS/MVS: Administration Reference forDFSMSdss, SC26-4929

v DFSMS/MVS: DFSMShsm Managing Your OwnData, SH21-1077

v DFSMS/MVS: Diagnosis Reference forDFSMSdfp, LY27-9606

v DFSMS/MVS: Macro Instructions for Data Sets,SC26-4913

v DFSMS/MVS: Managing Catalogs, SC26-4914

v DFSMS/MVS: Program Management,SC26-4916

v DFSMS/MVS: Storage AdministrationReference for DFSMSdfp, SC26-4920

v DFSMS/MVS: Using Advanced Services forData Sets, SC26-4921

v DFSMS/MVS: Utilities, SC26-4926

v MVS/DFP: Managing Non-VSAM Data Sets,SC26-4557

DFSORT

v DFSORT Application Programming: Guide,SC33-4035

Distributed Relational Database

v Data Stream and OPA Reference, SC31-6806

v Distributed Relational Database Architecture:Application Programming Guide, SC26-4773

v Distributed Relational Database Architecture:Connectivity Guide, SC26-4783

v Distributed Relational Database Architecture:Evaluation and Planning Guide, SC26-4650

v Distributed Relational Database Architecture:Problem Determination Guide, SC26-4782

v Distributed Relational Database ArchitectureReference, SC26-4651

v Distributed Relational Database: EveryManager's Guide, GC26-3195

v IBM Distributed Data Management (DDM)Reference Guide, SC21-9526

Bibliography 83

Page 92: Application Programming Guide and Reference

v IBM SQL Reference, SC26-8416

Education

v Dictionary of Computing, SC20-1699

v IBM Enterprise Systems Training SolutionsCatalog, GR28-5467

Enterprise System/9000 and EnterpriseSystem/3090

v Enterprise System/9000 and EnterpriseSystem/3090 Processor Resource/SystemManager Planning Guide, GA22-7123

FORTRAN

v VS FORTRAN Version 2: Language and LibraryReference, SC26-4221

v VS FORTRAN Version 2: Programming Guidefor CMS and MVS, SC26-4222

High Level Assembler

v High Level Assembler/MVS and VM and VSELanguage Reference, SC26-4940

v High Level Assembler/MVS and VM and VSEProgrammer's Guide, SC26-4941

Parallel Sysplex Library

v System/390 MVS Sysplex Application Migration,GC28-1211

v System/390 MVS Sysplex Hardware andSoftware Migration, GC28-1210

v System/390 MVS Sysplex Overview: AnIntroduction to Data Sharing and Parallelism,GC28-1208

v System/390 MVS Sysplex SystemsManagement, GC28-1209

v System/390 MVS 9672/9674 System Overview,GA22-7148

ICSF/MVS

v ICSF/MVS General Information, GC23-0093

IMS/ESA

v IMS Batch Terminal Simulator GeneralInformation, GH20-5522

v IMS/ESA Administration Guide: System,SC26-8013

v IMS/ESA Application Programming: DesignGuide, SC26-8016

v IMS/ESA Customization Guide, SC26-8020

v IMS/ESA Installation Volume 1: Installation andVerification, SC26-8023

v IMS/ESA Installation Volume 2: SystemDefinition and Tailoring, SC26-8024

v IMS/ESA Messages and Codes, SC26-8028

v IMS/ESA Operator's Reference, SC26-8030

v IMS/ESA Utilities Reference: System,SC26-8035

ISPF

v ISPF Version 4 Messages and Codes,SC34-4450

v ISPF Version 4 for MVS Dialog ManagementGuide, SC34-4213

v ISPF/PDF Version 4 for MVS Guide andReference, SC34-4258

v ISPF and ISPF/PDF Version 4 for MVSPlanning and Customization, SC34-4134

Language Environment for MVS & VM

v Language Environment for MVS & VMConcepts Guide, GC26-4786

v Language Environment for MVS & VMDebugging and Run-Time Messages Guide,SC26-4829

v Language Environment for MVS & VMInstallation and Customization, SC26-4817

v Language Environment for MVS & VMProgramming Guide, SC26-4818

v Language Environment for MVS & VMProgramming Reference, SC26-3312

MVS/ESA

v MVS/ESA Analyzing Resource MeasurementFacility Monitor I and Monitor II Reference andUser's Guide, LY28-1007

v MVS/ESA Analyzing Resource MeasurementFacility Monitor III Reference and User's Guide,LY28-1008

84 Application Programming Guide and Reference for Java™

Page 93: Application Programming Guide and Reference

v MVS/ESA Application Development Reference:Assembler Callable Services for OpenEditionMVS, SC23-3020

v MVS/ESA Data Administration: Utilities,SC26-4516

v MVS/ESA Diagnosis: Procedures, LY28-1844

v MVS/ESA Diagnosis: Tools and Service Aids,LY28-1845

v MVS/ESA Initialization and Tuning Guide,SC28-1451

v MVS/ESA Initialization and Tuning Reference,SC28-1452

v MVS/ESA Installation Exits, SC28-1459

v MVS/ESA JCL Reference, GC28-1479

v MVS/ESA JCL User's Guide, GC28-1473

v MVS/ESA JES2 Initialization and Tuning Guide,SC28-1453

v MVS/ESA MVS Configuration Program,GC28-1615

v MVS/ESA Planning: Global ResourceSerialization, GC28-1450

v MVS/ESA Planning: Operations, GC28-1441

v MVS/ESA Planning: Workload Management,GC28-1493

v MVS/ESA Programming: Assembler ServicesGuide, GC28-1466

v MVS/ESA Programming: Assembler ServicesReference, GC28-1474

v MVS/ESA Programming: Authorized AssemblerServices Guide, GC28-1467

v MVS/ESA Programming: Authorized AssemblerServices Reference, Volumes 1-4, GC28-1475,GC28-1476, GC28-1477, GC28-1478

v MVS/ESA Programming: ExtendedAddressability Guide, GC28-1468

v MVS/ESA Programming: Sysplex ServicesGuide, GC28-1495

v MVS/ESA Programming: Sysplex ServicesReference, GC28-1496

v MVS/ESA Programming: WorkloadManagement Services, GC28-1494

v MVS/ESA Routing and Descriptor Codes,GC28-1487

v MVS/ESA Setting Up a Sysplex, GC28-1449

v MVS/ESA SPL: Application Development Guide,GC28-1852

v MVS/ESA System Codes, GC28-1486

v MVS/ESA System Commands, GC28-1442

v MVS/ESA System Management Facilities(SMF), GC28-1457

v MVS/ESA System Messages Volume 1,GC28-1480

v MVS/ESA System Messages Volume 2,GC28-1481

v MVS/ESA System Messages Volume 3,GC28-1482

v MVS/ESA Using the Subsystem Interface,SC28-1502

Net.Data for OS/390

v Net.Data Language Environment Guide,http://www.software.ibm.com/data/net.data/docs

v Net.Data Programming Guide,http://www.software.ibm.com/data/net.data/docs

v Net.Data Reference Guide,http://www.software.ibm.com/data/net.data/docs

NetView

v NetView Installation and Administration Guide,SC31-8043

v NetView User's Guide, SC31-8056

ODBC

v ODBC 2.0 Programmer's Reference and SDKGuide, ISBN 1-55615-658-8

v Inside ODBC, ISBN 1-55615-815-7

OS/390

v OS/390 C/C++ Programming Guide, SC09-2362

v OS/390 C/C++ Run-Time Library Reference,SC28-1663

v OS/390 Information Roadmap, GC28-1727

v OS/390 Introduction and Release Guide,GC28-1725

v OS/390 JES2 Initialization and Tuning Guide,SC28-1791

v OS/390 JES3 Initialization and Tuning Guide,SC28-1802

Bibliography 85

Page 94: Application Programming Guide and Reference

v OS/390 Language Environment for OS/390 &VM Concepts Guide, GC28-1945

v OS/390 Language Environment for OS/390 &VM Customization, SC28-1941

v OS/390 Language Environment for OS/390 &VM Debugging Guide, SC28-1942

v OS/390 Language Environment for OS/390 &VM Programming Guide, SC28-1939

v OS/390 Language Environment for OS/390 &VM Programming Reference, SC28-1940

v OS/390 MVS Diagnosis: Procedures,LY28-1082

v OS/390 MVS Diagnosis: Tools and ServiceAids, LY28-1085

v OS/390 MVS Initialization and Tuning Guide,SC28-1751

v OS/390 MVS Initialization and TuningReference, SC28-1752

v OS/390 MVS Installation Exits, SC28-1753

v OS/390 MVS JCL Reference, GC28-1757

v OS/390 MVS JCL User's Guide, GC28-1758

v OS/390 MVS Planning: Global ResourceSerialization, GC28-1759

v OS/390 MVS Planning: Operations, GC28-1760

v OS/390 MVS Planning: Workload Management,GC28-1761

v OS/390 MVS Programming: AssemblerServices Guide, GC28-1762

v OS/390 MVS Programming: AssemblerServices Reference, GC28-1910

v OS/390 MVS Programming: AuthorizedAssembler Services Guide, GC28-1763

v OS/390 MVS Programming: AuthorizedAssembler Services Reference, Volumes 1-4,GC28-1764, GC28-1765, GC28-1766,GC28-1767

v OS/390 MVS Programming: Callable Servicesfor High-Level Languages, GC28-1768

v OS/390 MVS Programming: ExtendedAddressability Guide, GC28-1769

v OS/390 MVS Programming: Sysplex ServicesGuide, GC28-1771

v OS/390 MVS Programming: Sysplex ServicesReference, GC28-1772

v OS/390 MVS Programming: WorkloadManagement Services, GC28-1773

v OS/390 MVS Routing and Descriptor Codes,GC28-1778

v OS/390 MVS Setting Up a Sysplex, GC28-1779

v OS/390 MVS System Codes, GC28-1780

v OS/390 MVS System Commands, GC28-1781

v OS/390 MVS System Messages Volume 1,GC28-1784

v OS/390 MVS System Messages Volume 2,GC28-1785

v OS/390 MVS System Messages Volume 3,GC28-1786

v OS/390 MVS System Messages Volume 4,GC28-1787

v OS/390 MVS System Messages Volume 5,GC28-1788

v OS/390 Security Server (RACF) Auditor'sGuide, SC28-1916

v OS/390 Security Server (RACF) CommandLanguage Reference, SC28-1919

v OS/390 Security Server (RACF) General User'sGuide, SC28-1917

v OS/390 Security Server (RACF) SecurityAdministrator's Guide, SC28-1915

v OS/390 Security Server (RACF) SystemProgrammer's Guide, SC28-1913

v OS/390 SMP/E Reference, SC28-1806

v OS/390 SMP/E User's Guide, SC28-1740

v OS/390 RMF User's Guide, SC28-1949

v OS/390 TSO/E CLISTS, SC28-1973

v OS/390 TSO/E Command Reference,SC28-1969

v OS/390 TSO/E Customization, SC28-1965

v OS/390 TSO/E Messages, GC28-1978

v OS/390 TSO/E Programming Guide,SC28-1970

v OS/390 TSO/E Programming Services,SC28-1971

v OS/390 TSO/E User's Guide, SC28-1968

OS/390 OpenEdition

86 Application Programming Guide and Reference for Java™

Page 95: Application Programming Guide and Reference

v OS/390 OpenEdition DCE Administration Guide,SC28-1584

v OS/390 OpenEdition DCE Introduction,GC28-1581

v OS/390 R1 OE DCE Messages and Codes,ST01-0920

v OS/390 OpenEdition Command Reference,SC28-1892

v OS/390 OpenEdition Messages and Codes,SC28-1908

v OS/390 OpenEdition Planning, SC28-1890

v OS/390 OpenEdition User's Guide, SC28-1891

PL/I for MVS & VM

v IBM PL/I MVS & VM Language Reference,SC26-3114

v IBM PL/I MVS & VM Programming Guide,SC26-3113

OS PL/I

v OS PL/I Programming Language Reference,SC26-4308

v OS PL/I Programming Guide, SC26-4307

PROLOG

v IBM SAA AD/Cycle Prolog/MVS & VMProgrammer's Guide, SH19-6892

Query Management Facility

v Query Management Facility: Managing QMF forMVS, SC26-8218

v Query Management Facility: Reference,SC26-4716

v Query Management Facility: Using QMF,SC26-8078

Remote Recovery Data Facility

v Remote Recovery Data Facility ProgramDescription and Operations, LY37-3710

Resource Access Control Facility (RACF)

v External Security Interface (RACROUTE) MacroReference for MVS and VM, GC28-1366

v Resource Access Control Facility (RACF)Auditor's Guide, SC28-1342

v Resource Access Control Facility (RACF)Command Language Reference, SC28-0733

v Resource Access Control Facility (RACF)General Information Manual, GC28-0722

v Resource Access Control Facility (RACF)General User's Guide, SC28-1341

v Resource Access Control Facility (RACF)Security Administrator's Guide, SC28-1340

v Recource Access Control Facility (RACF)System Programmer's Guide, SC28-1343

Storage Management

v MVS/ESA Storage Management Library:Implementing System-Managed Storage,SC26-3123

v MVS/ESA Storage Management Library:Leading an Effective Storage AdministrationGroup, SC26-3126

v MVS/ESA Storage Management Library:Managing Data, SC26-3124

v MVS/ESA Storage Management Library:Managing Storage Groups, SC26-3125

v MVS Storage Management Library: StorageManagement Subsystem Migration PlanningGuide, SC26-4659

System/370 and System/390

v IBM System/370 ESA Principles of Operation,SA22-7200

v IBM System/390 ESA Principles of Operation,SA22-7205

v System/390 MVS Sysplex Hardware andSoftware Migration, GC28-1210

System Modification Program Extended(SMP/E)

v System Modification Program Extended(SMP/E) Reference, SC28-1107

v System Modification Program Extended(SMP/E) User's Guide, SC28-1302

System Network Architecture (SNA)

v SNA Formats, GA27-3136

v SNA LU 6.2 Peer Protocols Reference,SC31-6808

Bibliography 87

Page 96: Application Programming Guide and Reference

v SNA Transaction Programmer's ReferenceManual for LU Type 6.2, GC30-3084

v SNA/Management Services AlertImplementation Guide, GC31-6809

TCP/IP

v IBM TCP/IP for MVS: Customization &Administration Guide, SC31-7134

v IBM TCP/IP for MVS: Diagnosis Guide,LY43-0105

v IBM TCP/IP for MVS: Messages and Codes,SC31-7132

v IBM TCP/IP for MVS: Planning and MigrationGuide, SC31-7189

TSO Extensions

v TSO/E CLISTS, SC28-1876

v TSO/E Command Reference, SC28-1881

v TSO/E Customization, SC28-1872

v TSO/E Messages, GC28-1885

v TSO/E Programming Guide, SC28-1874

v TSO/E Programming Services, SC28-1875

v TSO/E User's Guide, SC28-1880

VS COBOL II

v VS COBOL II Application Programming Guidefor MVS and CMS, SC26-4045

v VS COBOL II Application Programming:Language Reference, SC26-4047

v VS COBOL II Installation and Customization forMVS, SC26-4048

VTAM

v Planning for NetView, NCP, and VTAM,SC31-8063

v VTAM for MVS/ESA Diagnosis, LY43-0069

v VTAM for MVS/ESA Messages and Codes,SC31-6546

v VTAM for MVS/ESA Network ImplementationGuide, SC31-6548

v VTAM for MVS/ESA Operation, SC31-6549

v VTAM for MVS/ESA Programming, SC31-6550

v VTAM for MVS/ESA Programming for LU 6.2,SC31-6551

v VTAM for MVS/ESA Resource DefinitionReference, SC31-6552

88 Application Programming Guide and Reference for Java™

Page 97: Application Programming Guide and Reference

Index

AAPI

JDBC 10application

Java, running 10JDBC support 7SQLJ support 15

assignment clauseSQLJ 48

attachment facilitiesCAF 54description 54RRSAF 54

authorization IDs, establishing 53

Bbinding a plan

SQLJ 35

CCAF 54case sensitivity

SQLJ 17collecting trace data

SQLJ 36comment

SQLJ 17compiling an SQLJ program 34configuring

JDBC 13SQLJ 29

connecting to a data sourcemultiple context support 54SQLJ 18

connection declaration clauseSQLJ 43

connection object 55connection sharing 56context clause

SQLJ 46creating a DBRM

SQLJ 34customizing a serialized profile

SQLJ 34customizing Java environment 13

Ddata source

connecting 10identifying 9

data typesequivalent SQLJ and SQL 20

db2profc commandoptions 34parameters 34

diagnosing SQLJ problems 36diagnosis utilities

SQLJ 37driver, JDBC 10

registering with DriverManager 18

Eenvironment variables

JDBC 13SQLJ 29

error handlingSQLJ 17

executable clauseSQLJ 46

execution context 25execution control and status

SQLJ 25

HHFS

data set, allocating 52structure, creating 52

host expressionSQLJ 16, 40

Iimplements clause

SQLJ 41installation

JDBC and SQLJ 51iterator

for positioned DELETE 24for positioned UPDATE 24

iterator declaration clauseSQLJ 44

JJava application

customizing environment 13running 10

java.sql.connection classuse by SQLJ 20valid methods for SQLJ 20

Java thread 55JDBC

advantages 7API 10configuring 13description 7

© Copyright IBM Corp. 1998 89

Page 98: Application Programming Guide and Reference

JDBC (continued)driver 10environment variables 13implementation 8installation 51ODBC, relationship with 7sample program 11security 53

Mmethods, invoking 10multiple context support

connecting when enabled 55connecting when not enabled 55description 54

multithreading 54

Nnamed iterator

example 23renaming result table columns for 24result set iterator 22

notices, legal 61

OODBC and JDBC 7

Ppositioned iterator

example 22result set iterator 21

problem diagnosisSQLJ 36

program preparationSQLJ 29

Rresult set iterator

data types in 20description 20positioned iterator 21retrieving rows in SQLJ 20, 21, 22

retrieving rows in SQLJnamed iterator example 23positioned iterator example 22with named iterators 22

RRSAF 54running a program

SQLJ 36

Ssample program

JDBC 11SQLJ 26

securityenvironment 53model 53

serialized profilecustomizing 34

SQLequivalent SQLJ data types 20

SQL statementformat in SQLJ 16handling errors in SQLJ 17

SQLJassignment clause 48basic concepts 16binding a plan 35case sensitivity 17collecting trace data 36comment 17connecting to a data source 18connection declaration clause 43context clause 46creating a DBRM 34db2profc command 34description 15environment variables 29equivalent SQL data types 20error handling 17executable clause 16, 46execution control and status 25format of SQL statement 16host expression 16, 40implements clause 41importing Java packages 18including code to access 18installation 51installing the run-time environment 29iterator declaration clause 44loading JDBC driver 18problem diagnosis 36program preparation 29result set iterator 20running a program 36running diagnosis utilities 36sample program 26security 53statement clause 47translating source code 32use of java.sql.connection class 20valid SQL statements 16with clause 41, 42

SQLJ applicationwriting 16

SQLJ execution context 25sqlj.runtime.ExecutionContext

methods called in applications 57sqlj.runtime.ForUpdate

for positioned UPDATE and DELETE 58sqlj.runtime.NamedIterator

methods called in applications 58

90 Application Programming Guide and Reference for Java™

Page 99: Application Programming Guide and Reference

sqlj.runtime.PositionedIteratormethods called in applications 59

statement clauseSQLJ 47

syntax diagrams, how to read 2

Ttarget data source, identifying 9thread, Java 55translating source code

SQLJ 32

Vvalid SQL statements

SQLJ 16

Wwith clause

SQLJ 41, 42with positioned iterators 21with result set iterators 20

Index 91

Page 100: Application Programming Guide and Reference

92 Application Programming Guide and Reference for Java™

Page 101: Application Programming Guide and Reference
Page 102: Application Programming Guide and Reference

IBMR

Program Number: 5655-DB2

Printed in the United States of Americaon recycled paper containing 10%recovered post-consumer fiber.