Neoview Guide to Stored Procedures in Java (R2.5)

This subsection covers these topics related to output parameters:
“Using Arrays for Output Parameters” (page 25)
“Type Mapping of Output Parameters” (page 25)
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.
IMPORTANT: 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, ArrayIndexOutOfBounds.
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:
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 (page 65).
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
data type. See Table 3-1 (page 24). The SQL data type must then map to a compatible data type
in the calling application. For the client application programming interfaces (APIs) that support
SPJs and for cross-references to the appropriate manuals for type mappings between Neoview
SQL and each API, see Chapter 7 (page 51).
Returning Stored Procedure Result Sets
Neoview SQL supports SPJs that return stored procedure result sets. A stored procedure result
set is a cursor that is left open after the SPJ method executes (that is, after the CALL statement
executes successfully). After the CALL statement executes successfully, the calling application
can issue requests to open and then retrieve multiple rows of data from the returned result sets.
An SPJ method returns an ordered collection of result sets to the calling application by executing
SELECT statements and placing each returned ResultSet object into a one-element Java array
of type java.sql.ResultSet[]. The java.sql.ResultSet[] array is part of the Java
method's signature and is recognized by Neoview SQL as a container for a single stored procedure
result set.
Place the java.sql.ResultSet[] parameters after the other Java parameters, if any, in the
Java signature. If you do not place the java.sql.ResultSet[] parameters after the other
Guidelines for Writing SPJ Methods 25