SQL/MX Guide to Stored Procedures in Java (G06.24+, H06.03+)

Writing SPJ Methods
HP NonStop SQL/MX Guide to Stored Procedures in Java523727-004
3-3
Returning Output Values From the Java Method
Using Arrays for Output Parameters
You must use arrays for the output parameters of a Java method because of how Java
handles the arguments of a method. Java supports arguments that are passed by
value to a method and does not support arguments that are passed by reference. As a
result, Java primitive types can be passed only to a method, not out of a method.
Because a Java array is an object, its reference is passed by value to a method, and
changes to the array are visible to the caller of the method. Therefore, arrays must be
used for output parameters in a Java method.
An output parameter accepts only one value in the first element of the array at index 0.
Any attempt to return more than one value to an output parameter results in a Java
exception.
For each output parameter, specify the Java type followed by empty square brackets
([]) to indicate that the type is an array. For example, specify an int type as int[]
for an output parameter in the Java signature.
To return multiple values from a Java method, use an output parameter for each
returned value. For example, the supplierInfo() method returns a suppliers
name, address, city, state, and post code, each as a single string in an output
parameter:
public static void supplierInfo(BigDecimal suppNum,
String[] suppName,
String[] streetAddr,
String[] cityName,
String[] stateName,
String[] postCode)
throws SQLException
{
...
The supplyQuantities() method returns an average quantity, a minimum quantity,
and a maximum quantity to separate output parameters of the integer type:
public static void supplyQuantities(int[] avgQty,
int[] minQty,
int[] maxQty)
throws SQLException
{
...
For more information about the SPJ examples, see Appendix A, Sample SPJs.
Type Mapping of Output Parameters
When writing an SPJ method, consider how the output of the SPJ will be used in the
calling application. For output parameters, the Java data type of the SPJ method must
map to an SQL/MX data type. See Table 3-1 on page 3-2. The SQL/MX data type must
then map to a compatible data type in the calling application. See Section 5, Invoking
SPJs in NonStop SQL/MX, for the client application programming interfaces (APIs) that