SQL/MX Programming Manual for Java

SQLJ Programming
HP NonStop SQL/MX Programming Manual for Java523726-003
3-27
Host Variables and Expressions
Host Variables and Expressions
To pass data between an SQLJ program and SQL/MX or SQL/MP tables, use Java
variables and expressions as host variables and host expressions in an SQLJ
executable clause. Host variables and host expressions begin with a colon (:). For the
syntax of host variables and expressions, see Host Expression on page A-6.
Input and Output Modes
There are two modes of host variables and expressions: input and output. SQLJ infers
the mode of a host variable or expression based on its use within the SQLJ executable
clause. Optionally, you can explicitly specify the mode of a host variable or expression
as IN, OUT, or INOUT, but this coding is unnecessary.
Input Host Variables and Expressions (IN or INOUT)
Input host variables and expressions pass Java data to an SQLJ clause for evaluation
by the database. Input host variables and expressions are not part of an INTO list or
the left-hand part of an assignment expression. In this UPDATE statement, Salary is
an input host variable:
java.math.BigDecimal Salary =
new java.math.BigDecimal("60000.00");
...
#sql {UPDATE employee
SET salary = :Salary
WHERE empnum = 300
};
...
See Input Assignability on page 3-32.
Output Host Variables and Expressions (OUT or INOUT)
Output host variables and expressions accept SQL data from an SQLJ clause and
store it in a Java variable. Output host variables are typically part of an INTO list or the
left-hand part of an assignment expression. In this SELECT statement, empname is an
output host variable:
String empname = null;
...
#sql {SELECT last_name
INTO :empname
FROM employee
WHERE empnum = 65
};
...
See Output Assignability on page 3-35.