SQL/MX Programming Manual for Java

SQLJ Programming
HP NonStop SQL/MX Programming Manual for Java523726-003
3-2
SQLJ Clause
Declaration Clauses
An SQLJ declaration clause can be a connection declaration clause or an iterator
declaration clause. An SQLJ declaration clause causes the SQLJ translator to
generate a Java class, and the scope and visibility of the generated Java class depend
on the placement of the SQLJ declaration clause.
Placement of Declaration Clauses
Placing an SQLJ declaration clause at the beginning of an SQLJ source file (that is, at
the top-level scope) outside of classes in the source file makes the generated class
globally available to other classes. Placing an SQLJ declaration clause within another
class or a nested class makes the generated class locally available to that class. You
cannot place an SQLJ declaration clause inside the body of a method.
Connection Declaration Clause
A connection declaration clause defines an explicit connection context class, which the
SQLJ translator replaces with a Java class definition. A connection context establishes
a specific connection with the database. For the syntax of the connection declaration
clause, see Connection Declaration Clause on page A-1. For information about
declaring connection contexts, see Connection Contexts on page 3-8.
Iterator Declaration Clause
An iterator declaration clause defines a type of iterator class—positioned or named. An
iterator retrieves multiple rows of data from a result set and is similar to a JDBC result
set or a cursor in a C or COBOL program. For the syntax of the iterator declaration
clause, see Iterator Declaration Clause on page A-2. For information about declaring
iterators, see Iterators and Result Sets on page 3-48.
Examples
This SQLJ clause contains a connection declaration clause:
#sql context CtxClassName;
This SQLJ clause contains an iterator declaration clause for a positioned iterator:
#sql iterator ItrClassName (String, BigDecimal);
Executable Clauses
An SQLJ executable clause contains an SQL statement enclosed in curly braces ({}).
The SQL statement inside the braces has no terminating character. An executable
clause can occur anywhere a Java executable statement can occur within a method or
a constructor.
The curly braces delimit the SQL statement, setting it apart from the Java code and
designating that it be processed according to the syntactical rules of SQL. In an
embedded SQL statement within curly braces, the SQL keywords and identifiers (for