SQL/MX Programming Manual for Java

SQLJ Programming
HP NonStop SQL/MX Programming Manual for Java523726-003
3-29
Host Variables
VALUES (:empNum, :firstName, :lastName,
:deptNum, :jobCode, :salary)
};
...
Example—UPDATE Statement
This UPDATE statement updates the salary of employee number 300 with the value of
the host variable:
java.math.BigDecimal Salary =
new java.math.BigDecimal("60000.00");
...
#sql {UPDATE employee
SET salary = :Salary
WHERE empnum = 300
};
...
Case Sensitivity
The host variables and expressions are processed according to the syntactical rules of
Java. Therefore, the variable names are case-sensitive. For example, the host variable
:EmpName is not the same as :empname.
Data Type Compatibility
The value of a host variable or the result of a host expression must be type compatible
with its use in the SQL statement. Many type combinations are possible because Java
provides conversions between string and numeric values with certain restrictions. For
example, if the conversion is from a string to a numeric value, the string must consist of
the character literal equivalent of the numeric value. For input and output assignability,
see Data Type Support on page 3-32.
Null Values
If an input host variable (IN mode) has a Java primitive data type, it cannot pass a null
value to the database. To pass a null value to the database, use a Java wrapper class
instead of a Java primitive data type for the input host variable. See Input Assignability
on page 3-32.
If an output host variable (OUT or INOUT mode) has a Java primitive data type, it
cannot accept a null value from the database and throws an SQLNullException
exception. In this case, use a try-catch block to catch and handle a null value, or
avoid the problem by using a Java wrapper class instead of a Java primitive data type
for the output host variable. See Output Assignability on page 3-35.