JDBC - Callable Statement (Stored Procedure)


The CallableStatement objects interface adds methods to the statement interface for retrieving output parameter values returned from stored procedures.

See CallableStatement objects


CallableStatement objects may take three types of parameters: IN, OUT, and INOUT.

CallableStatement object for calling the stored procedure ‘validate’, which has a return parameter and two other parameters.


CallableStatement cstmt = conn.prepareCall(
“{? = call validate(?, ?)}”);

CallableStatement cstmt = con.prepareCall(
"{CALL PROC(?, "Literal_Value", ?)}");
cstmt.setString(1, "First");
cstmt.setString(2, "Third");

// out parameter
cstmt.registerOutParameter(1, java.sql.Types.STRING);
cstmt.registerOutParameter(2, java.sql.Types.FLOAT);
// Retrieve OUT parameters
String name = cstmt.getString(1);
float number = cstmt.getFloat(2);

// the two parameter markers have the ordinal values 1 and 2.
cstmt.setFloat("PARAM_5", 150.25);

Powered by ComboStrap