SQL/MX Programming Manual for Java
SQLJ Programming
HP NonStop SQL/MX Programming Manual for Java—523726-003
3-30
Host Expressions
You can test the value of the Java variable for a null value (instead of using NULL
indicators as in embedded programs in C or COBOL). See this example:
String empname = null;
...
#sql {SELECT last_name
INTO :empname
FROM employee
WHERE empnum = 65
};
...
if (empname == null) {
// Handle null value
}
Host Expressions
You can use complex host expressions in addition to using simple host variables. For
example, you might use a method call on the right-hand side of a predicate or an
assignment statement. Or, you might use an indexed array element on the left-hand
side as a target host expression. The result of a host expression must be a single
value.
Example
The host expression, :(Salary+500), performs an arithmetic operation and passes
its result to SQL/MX for evaluation:
...
#sql { SELECT last_name
INTO :empname
FROM employee
WHERE salary = :(Salary+500)
AND deptnum = 3100
};
Order of Evaluation
Before executing an SQL statement, SQLJ evaluates the assignment of host variables
and expressions in left-to-right order according to their occurrence in the SQL
statement. This evaluation prevents any unwanted side effects.
Within a single host expression, the evaluation of the expression follows the Java
precedence rules. Use parentheses within a host expression to enforce the order of
evaluation.
Note. For better performance in online transaction processing (OLTP) environments, avoid
computations within host variables (that is, host variable expressions). Instead, perform the
computation outside the SQL statement and assign the result to a host variable.