diff --git a/org.springframework.jdbc/src/main/java/org/springframework/jdbc/core/ArgPreparedStatementSetter.java b/org.springframework.jdbc/src/main/java/org/springframework/jdbc/core/ArgPreparedStatementSetter.java index e0d8c0ca87e..3f84a17e5ad 100644 --- a/org.springframework.jdbc/src/main/java/org/springframework/jdbc/core/ArgPreparedStatementSetter.java +++ b/org.springframework.jdbc/src/main/java/org/springframework/jdbc/core/ArgPreparedStatementSetter.java @@ -43,17 +43,29 @@ class ArgPreparedStatementSetter implements PreparedStatementSetter, ParameterDi if (this.args != null) { for (int i = 0; i < this.args.length; i++) { Object arg = this.args[i]; - if (arg instanceof SqlParameterValue) { - SqlParameterValue paramValue = (SqlParameterValue) arg; - StatementCreatorUtils.setParameterValue(ps, i + 1, paramValue, paramValue.getValue()); - } - else { - StatementCreatorUtils.setParameterValue(ps, i + 1, SqlTypeValue.TYPE_UNKNOWN, arg); - } + doSetValue(ps, i, arg); } } } + /** + * Set the value for prepared statements specified parameter index using the passed in value. + * This method can be overridden by sub-classes if needed. + * @param ps the PreparedStatement + * @param parameterPosition index of the parameter position + * @param argValue the value to set + * @throws SQLException + */ + protected void doSetValue(PreparedStatement ps, int parameterPosition, Object argValue) throws SQLException { + if (argValue instanceof SqlParameterValue) { + SqlParameterValue paramValue = (SqlParameterValue) argValue; + StatementCreatorUtils.setParameterValue(ps, parameterPosition + 1, paramValue, paramValue.getValue()); + } + else { + StatementCreatorUtils.setParameterValue(ps, parameterPosition + 1, SqlTypeValue.TYPE_UNKNOWN, argValue); + } + } + public void cleanupParameters() { StatementCreatorUtils.cleanupParameters(this.args); } diff --git a/org.springframework.jdbc/src/main/java/org/springframework/jdbc/core/ArgTypePreparedStatementSetter.java b/org.springframework.jdbc/src/main/java/org/springframework/jdbc/core/ArgTypePreparedStatementSetter.java index f8cc54a3f36..235ed6b0f52 100644 --- a/org.springframework.jdbc/src/main/java/org/springframework/jdbc/core/ArgTypePreparedStatementSetter.java +++ b/org.springframework.jdbc/src/main/java/org/springframework/jdbc/core/ArgTypePreparedStatementSetter.java @@ -53,7 +53,7 @@ class ArgTypePreparedStatementSetter implements PreparedStatementSetter, Paramet public void setValues(PreparedStatement ps) throws SQLException { - int argIndx = 1; + int parameterPosition = 1; if (this.args != null) { for (int i = 0; i < this.args.length; i++) { Object arg = this.args[i]; @@ -65,21 +65,38 @@ class ArgTypePreparedStatementSetter implements PreparedStatementSetter, Paramet Object[] valueArray = ((Object[])entry); for (int k = 0; k < valueArray.length; k++) { Object argValue = valueArray[k]; - StatementCreatorUtils.setParameterValue(ps, argIndx++, this.argTypes[i], argValue); + doSetValue(ps, parameterPosition, this.argTypes[i], argValue); + parameterPosition++; } } else { - StatementCreatorUtils.setParameterValue(ps, argIndx++, this.argTypes[i], entry); + doSetValue(ps, parameterPosition, this.argTypes[i], entry); + parameterPosition++; } } } else { - StatementCreatorUtils.setParameterValue(ps, argIndx++, this.argTypes[i], arg); + doSetValue(ps, parameterPosition, this.argTypes[i], arg); + parameterPosition++; } } } } + /** + * Set the value for the prepared statement's specified parameter position using the passed in + * value and type. This method can be overridden by sub-classes if needed. + * @param ps the PreparedStatement + * @param parameterPosition index of the parameter position + * @param argType the argument type + * @param argValue the argument value + * @throws SQLException + */ + protected void doSetValue(PreparedStatement ps, int parameterPosition, int argType, Object argValue) + throws SQLException { + StatementCreatorUtils.setParameterValue(ps, parameterPosition, argType, argValue); + } + public void cleanupParameters() { StatementCreatorUtils.cleanupParameters(this.args); }