Skip to content

Add option to check for matching number of arguments for a given PreparedStatement in ArgPreparedStatementSetter and enhance JdbcTemplate to optionally use it [SPR-5678] #10349

Closed
@spring-projects-issues

Description

@spring-projects-issues

Joris Kuipers opened SPR-5678 and commented

Currently, ArgPreparedStatementSetter.setValues simply applies the values in the args array it was created with to the given PreparedStatement. That means that if there are less arguments than placeholders, the remaining placeholders will be null. This is valid behavior in some cases, but in many cases I'd argue that this indicates a programmer error (forgetting a parameter).
It might be nice to add an option to setValues to optionally check for a matching count of arguments and placeholders. The latter can be obtained from the PreparedStatement's ParameterMetaData. The JdbcTemplate can then be updated to enable this feature so this programming error would be caught early, instead of indirectly by running the statement with accidental null values.
By disabling the option by default everything remains backwards compatible.


Affects: 2.5.6

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: dataIssues in data modules (jdbc, orm, oxm, tx)status: declinedA suggestion or change that we don't feel we should currently applytype: enhancementA general enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions