Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 opened this issue Apr 15, 2009 · 1 comment
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

Comments

@spring-projects-issues
Copy link
Collaborator

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

@spring-projects-issues
Copy link
Collaborator Author

Thomas Risberg commented

This is only an issue for HSQL - other databases throw some kind of SQLException:

Oracle: java.sql.SQLException: Missing IN or OUT parameter at index:: 3
MySQL: java.sql.SQLException: No value specified for parameter 3
DB2: com.ibm.db2.jcc.c.SqlException: [ibm][db2][jcc][10143][10845] Invalid parameter 3: Parameter is not set nor registered.
MSSQL: com.microsoft.sqlserver.jdbc.SQLServerException: The value is not set for the parameter number 3.
Derby: java.sql.SQLException: At least one parameter to the current statement is uninitialized.
H2: org.h2.jdbc.JdbcSQLException: Parameter #3 is not set [90012-71]

So the conclucions is that this is not worth fixing since it would add additional complexity.

@spring-projects-issues spring-projects-issues added status: declined A suggestion or change that we don't feel we should currently apply in: data Issues in data modules (jdbc, orm, oxm, tx) type: enhancement A general enhancement labels Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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
Projects
None yet
Development

No branches or pull requests

1 participant