Skip Headers

# Specifying an Output Parameter

Previous

Next

Output parameters enable the stored procedure to return additional information. You can use output parameters to define a `ReadObjectQuery` if they return all the fields required to build the object.

In Example: Stored Procedure Call with an Output Parameter, you specify the parameter IS_VALID as an output parameter using the `StoredProcedureCall` method `addNamedOutputArgument`.

Stored Procedure Call with an Output Parameter

    StoredProcedureCall call = new StoredProcedureCall();
    call.setProcedureName("CHECK_VALID_POSTAL_CODE");
    call.addNamedArgument("POSTAL_CODE");
    call.addNamedOutputArgument(
        "IS_VALID",    // procedure parameter name
        "IS_VALID",    // out argument field name
        Integer.class  // Java type corresponding to type returned by procedure
    );
    ValueReadQuery query = new ValueReadQuery();
    query.setCall(call);
    query.addArgument("POSTAL_CODE");
    Vector parameters = new Vector();
    parameters.addElement("L5J1H5");
    Number isValid = (Number)session.executeQuery(query,parameters);

Note: Not all databases support the use of output parameters to return data. However, because these databases generally support returning result sets from stored procedures, they do not require output parameters.

If you are using an Oracle database, you can make use of TopLink cursor and stream query results.