SQL/MX 3.2.1 Guide to Stored Procedures in Java (H06.26+, J06.15+)
Table 2 Mapping of Java Data Types to SQL/MX Data Types (continued)
Maps to SQL/MX Data Type...Java D ata Type
VARYING NATIONAL CHAR[ACTER] NATIONAL
CHAR[ACTER] VARYING
DATEjava.sql.Date
TIMEjava.sql.Time
TIMESTAMPjava.sql.Timestamp
NUMERICDEC[IMAL]PIC[TURE] S9java.math.BigDecimal
SMALLINTshort
INT[EGER]int or java.lang.Integer*
LARGEINTlong or java.lang.Long*
FLOATdouble or java.lang.Double*
REALfloat or java.lang.Float*
DOUBLE PRECISIONdouble or java.lang.Double*
* Choose a Java wrapper class if you plan to pass null values as arguments to or from the method. See Null Input and
Output (page 52).
Output parameters in the Java signature must be arrays (for example, int[] or String[]) that
accept only one value in the first element of the array at index 0. For more information, see Returning
Output Values From the Java Method.
Returning Output Values From the Java Method
Output parameters in the Java signature must be parameter arrays that accept one value in the
first element of the array at index 0. This subsection covers these topics related to output parameters:
• Using Arrays for Output Parameters (page 50)
• Type Mapping of Output Parameters (page 51)
• Stored Procedure Result Sets (page 51)
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 supplier's 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,
50 Writing SPJ Methods










