You can use named parameters to map host variable names in a CALL statement to the parameter names in the stored procedure definition.
With named parameters, you do not need to specify parameters in the CALL statement in the same order that they appear in the stored procedure definition. In addition, you do not need to specify all parameters in the CALL statement. Unspecified parameters take the default values that are specified in the stored procedure definition.
To use named parameters with CALL statements, follow these steps:
CREATE PROCEDURE SALS (
OUT retcode INTEGER,
IN lowsal DOUBLE,
IN medsal DOUBLE,
IN highsal DOUBLE DEFAULT 100000,
IN department CHAR(3) DEFAULT '---')
SPECIFIC JDBC_SALS
DYNAMIC RESULT SETS 0
DETERMINISTIC
LANGUAGE JAVA
PARAMETER STYLE JAVA
NO DBINFO
FENCED
THREADSAFE
MODIFIES SQL DATA
PROGRAM TYPE SUB
EXTERNAL NAME 'MYJAR:MyClass.sals'
The input parameters in the CALL statement are represented
by named parameters. The third and fourth parameters are called with
the default values for the stored procedure. The numbers to the right
of selected statements correspond to the previously-described steps.double hvLowSal=10000; // Host variables for input parameters
double hvMedSal=50000;
int hvRetCode; // Host variable for output parameter
…
#sql [myConnCtx] {CALL SALS(retcode=>:OUT hvRetCode, 1
lowsal=>:IN hvLowSal,
medsal=>:IN hvMedSal,
highsal=>DEFAULT)};
// Call the stored procedure.
// Implicitly use the default
// value for the last parameter
// by omitting it.
System.out.println("Return code from SALS call: " + hvRetCode); 2