Skip to content

CallableStatement: using named parameters to specify only certain parameter values #553

Open
@gordthompson

Description

@gordthompson

(ref: this Stack Overflow question)

Section 13.3.2 of the JDBC 4.2 specification says

Named parameters can be used to specify only the values that have no default value.

In CODE EXAMPLE 13-21, the procedure COMPLEX_PROC takes ten parameters, but only the first and fifth parameters, PARAM_1 and PARAM_5, are required.

CallableStatement cstmt = con.prepareCall("{CALL COMPLEX_PROC(?, ?)}";
cstmt.setString("PARAM_1", "Price");
cstmt.setFloat("PARAM_5", 150.25);

I just tried this with 6.3.4.jre8-preview.jar and I couldn't get it to work. It seemed that I had to provide a parameter placeholder for every possible parameter, ((?,?,?,?,?,?,?,?,?,?) in the above example), and I didn't see a way to specify DEFAULT for a parameter that I would have otherwise simply omitted.

In other words, it seems like named parameter support for CallableStatement in mssql-jdbc is currently limited to allowing us to specify the parameters in any order, but not to "pick and choose" the parameters we actually supply.

Have I missed something?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions