SQLJ host-expression

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

Syntax

Read syntax diagramSkip visual syntax diagram:INOUTINOUTsimple-variable( complex-expression)INDICATOR:simple-variable( complex-expression)

Description

:
Indicates that the variable or expression that follows is a host expression. The colon must immediately precede the variable or expression.
IN|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). The default is IN.
simple-variable
Specifies a Java unqualified identifier.
complex-expression
Specifies a Java expression that results in a single value.
INDICATOR :simple-variable or INDICATOR :(complex-expression)
Specifies the optional indicator variable for the corresponding Java host variable. The data type of the indicator variable must be the Java short type. The only valid values for :simple-variable or :(complex-expression) are:

For customized applications, and for input, only these values are valid:

Indicator value Equivalent constant Meaning of value
-1 sqlj.runtime.ExecutionContext.DBNull Null
-2, -3, -4, -6   Null
-5 sqlj.runtime.ExecutionContext.DBDefault Default
-7 sqlj.runtime.ExecutionContext.DBUnassigned Unassigned
short-value >=0 sqlj.runtime.ExecutionContext.DBNonNull Non-null

For uncustomized applications, and for input, only these values are valid:

Indicator value Equivalent constant Meaning of value
-1 sqlj.runtime.ExecutionContext.DBNull Null
-7 <= short-value < -1   Null
0 sqlj.runtime.ExecutionContext.DBNonNull Non-null
short-value >0   Non-null

For customized or uncustomized applications, and for output, SQLJ sets one of these values:

Indicator value Equivalent constant Meaning of value
-1 sqlj.runtime.ExecutionContext.DBNull Retrieved value is SQL NULL
0   Retrieved value is not SQL NULL

Usage notes

  • A complex expression must be enclosed in parentheses.
  • ANSI/ISO rules govern where a host expression can appear in a static SQL statement.
  • Indicator variables are required in the following cases:
    • For input, when a Java primitive type is used to assign the NULL value to a table column.
    • For output, when a Java primitive type is used for a host variable, and the source column can return NULL values.

      If an SQL NULL value is returned, and no indicator variable is defined, an SQLNullException is thrown.

    Indicator variables are not required for input or output of a Java null value as an SQL NULL, if the data type of the host variable is:
    • The data type of a Java class
    • A custom database type that the driver supports
  • , … variable-n
  • For output, indicator variables are valid in the following types of statements:
    • CALL statement with OUT or INOUT parameters
    • FETCH positioned-iterator INTO variable-1, … variable-n
    • SELECT column-1, … column-n INTO variable-1, … variable-n