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
Labels
in: data
Issues in data modules (jdbc, orm, oxm, tx)
status: declined
A suggestion or change that we don't feel we should currently apply
type: enhancement
A general enhancement
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
The text was updated successfully, but these errors were encountered: