SQL/MX Programming Manual for Java

HP NonStop SQL/MX Programming Manual for Java523726-003
3-1
3 SQLJ Programming
This section explains how to write an SQLJ program and covers basic SQLJ
programming constructs:
Basic Elements of an SQLJ Program on page 3-1
Code Initialization on page 3-4
Connection Contexts on page 3-8
Execution Contexts on page 3-20
Multithreading on page 3-23
Host Variables and Expressions on page 3-27
Data Type Support on page 3-32
Character String Literals on page 3-45
Iterators and Result Sets on page 3-48
Calling Stored Procedures in Java on page 3-59
Handling Exception Conditions on page 3-60
For advanced programming constructs, such as static and dynamic SQL and the
behavior of various SQL statements in an SQLJ program, see Section 4, SQL/MX
Programming Considerations.
Basic Elements of an SQLJ Program
An SQLJ program contains the basic elements of a Java program, such as the
package statement, imported packages or classes, class declarations, variable
declarations, constructors, methods, instantiated objects, assignment statements, and
control flow statements. In addition to Java constructs, SQLJ programs include
embedded SQL statements in special SQLJ clauses.
For examples of SQLJ programs, see Appendix C, Sample Programs.
SQLJ Source File
Code an SQLJ program in an SQLJ source file. An SQLJ source file has the .sqlj
extension. The SQLJ translator recognizes only the .sqlj extension as an SQLJ
source file, so do not use other extensions for an SQLJ source file.
SQLJ Clause
An SQLJ clause specifies an embedded SQLJ statement inside a Java program. An
SQLJ clause always begins with the characters #sql and is terminated by a semicolon
(;):
#sql {...};
An SQLJ clause can contain a connection declaration clause, an iterator declaration
clause, or an executable clause. In an SQLJ program, all SQL statements are
contained in SQLJ executable clauses.
For the syntax of the SQLJ clause, see SQLJ Clause on page A-1.