Skip to content

Commit f449b5a

Browse files
committed
JDBC parameter binding uses JDBC 3.0 ParameterMetaData (if available) for type determination
In sync with 3.2.1 now, containing minor modifications for defensiveness against the JDBC driver. Issue: SPR-10084
1 parent bdc8d79 commit f449b5a

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

org.springframework.jdbc/src/main/java/org/springframework/jdbc/core/PreparedStatementCreatorFactory.java

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2013 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -48,7 +48,7 @@ public class PreparedStatementCreatorFactory {
4848
/** The SQL, which won't change when the parameters change */
4949
private final String sql;
5050

51-
/** List of SqlParameter objects. May not be <code>null</code>. */
51+
/** List of SqlParameter objects. May not be {@code null}. */
5252
private final List<SqlParameter> declaredParameters;
5353

5454
private int resultSetType = ResultSet.TYPE_FORWARD_ONLY;
@@ -144,31 +144,31 @@ public void setNativeJdbcExtractor(NativeJdbcExtractor nativeJdbcExtractor) {
144144

145145
/**
146146
* Return a new PreparedStatementSetter for the given parameters.
147-
* @param params list of parameters (may be <code>null</code>)
147+
* @param params list of parameters (may be {@code null})
148148
*/
149-
public PreparedStatementSetter newPreparedStatementSetter(List params) {
149+
public PreparedStatementSetter newPreparedStatementSetter(List<?> params) {
150150
return new PreparedStatementCreatorImpl(params != null ? params : Collections.emptyList());
151151
}
152152

153153
/**
154154
* Return a new PreparedStatementSetter for the given parameters.
155-
* @param params the parameter array (may be <code>null</code>)
155+
* @param params the parameter array (may be {@code null})
156156
*/
157157
public PreparedStatementSetter newPreparedStatementSetter(Object[] params) {
158158
return new PreparedStatementCreatorImpl(params != null ? Arrays.asList(params) : Collections.emptyList());
159159
}
160160

161161
/**
162162
* Return a new PreparedStatementCreator for the given parameters.
163-
* @param params list of parameters (may be <code>null</code>)
163+
* @param params list of parameters (may be {@code null})
164164
*/
165165
public PreparedStatementCreator newPreparedStatementCreator(List<?> params) {
166166
return new PreparedStatementCreatorImpl(params != null ? params : Collections.emptyList());
167167
}
168168

169169
/**
170170
* Return a new PreparedStatementCreator for the given parameters.
171-
* @param params the parameter array (may be <code>null</code>)
171+
* @param params the parameter array (may be {@code null})
172172
*/
173173
public PreparedStatementCreator newPreparedStatementCreator(Object[] params) {
174174
return new PreparedStatementCreatorImpl(params != null ? Arrays.asList(params) : Collections.emptyList());
@@ -178,7 +178,7 @@ public PreparedStatementCreator newPreparedStatementCreator(Object[] params) {
178178
* Return a new PreparedStatementCreator for the given parameters.
179179
* @param sqlToUse the actual SQL statement to use (if different from
180180
* the factory's, for example because of named parameter expanding)
181-
* @param params the parameter array (may be <code>null</code>)
181+
* @param params the parameter array (may be {@code null})
182182
*/
183183
public PreparedStatementCreator newPreparedStatementCreator(String sqlToUse, Object[] params) {
184184
return new PreparedStatementCreatorImpl(
@@ -225,7 +225,7 @@ public PreparedStatementCreatorImpl(String actualSql, List parameters) {
225225
}
226226

227227
public PreparedStatement createPreparedStatement(Connection con) throws SQLException {
228-
PreparedStatement ps = null;
228+
PreparedStatement ps;
229229
if (generatedKeysColumnNames != null || returnGeneratedKeys) {
230230
try {
231231
if (generatedKeysColumnNames != null) {
@@ -263,7 +263,7 @@ public void setValues(PreparedStatement ps) throws SQLException {
263263
int sqlColIndx = 1;
264264
for (int i = 0; i < this.parameters.size(); i++) {
265265
Object in = this.parameters.get(i);
266-
SqlParameter declaredParameter = null;
266+
SqlParameter declaredParameter;
267267
// SqlParameterValue overrides declared parameter metadata, in particular for
268268
// independence from the declared parameter position in case of named parameters.
269269
if (in instanceof SqlParameterValue) {

org.springframework.jdbc/src/main/java/org/springframework/jdbc/core/StatementCreatorUtils.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2013 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -93,7 +93,7 @@ public abstract class StatementCreatorUtils {
9393
/**
9494
* Derive a default SQL type from the given Java type.
9595
* @param javaType the Java type to translate
96-
* @return the corresponding SQL type, or <code>null</code> if none found
96+
* @return the corresponding SQL type, or {@code null} if none found
9797
*/
9898
public static int javaTypeToSqlParameterType(Class javaType) {
9999
Integer sqlType = javaTypeToSqlTypeMap.get(javaType);
@@ -233,7 +233,7 @@ private static void setNull(PreparedStatement ps, int paramIndex, int sqlType, S
233233
try {
234234
pmd = ps.getParameterMetaData();
235235
}
236-
catch (AbstractMethodError err) {
236+
catch (Throwable ex) {
237237
// JDBC driver not compliant with JDBC 3.0
238238
// -> proceed with database-specific checks
239239
}
@@ -381,7 +381,7 @@ private static boolean isStringValue(Class inValueType) {
381381
}
382382

383383
/**
384-
* Check whether the given value is a <code>java.util.Date</code>
384+
* Check whether the given value is a {@code java.util.Date}
385385
* (but not one of the JDBC-specific subclasses).
386386
*/
387387
private static boolean isDateValue(Class inValueType) {
@@ -394,7 +394,7 @@ private static boolean isDateValue(Class inValueType) {
394394
/**
395395
* Clean up all resources held by parameter values which were passed to an
396396
* execute method. This is for example important for closing LOB values.
397-
* @param paramValues parameter values supplied. May be <code>null</code>.
397+
* @param paramValues parameter values supplied. May be {@code null}.
398398
* @see DisposableSqlTypeValue#cleanup()
399399
* @see org.springframework.jdbc.core.support.SqlLobValue#cleanup()
400400
*/
@@ -407,7 +407,7 @@ public static void cleanupParameters(Object[] paramValues) {
407407
/**
408408
* Clean up all resources held by parameter values which were passed to an
409409
* execute method. This is for example important for closing LOB values.
410-
* @param paramValues parameter values supplied. May be <code>null</code>.
410+
* @param paramValues parameter values supplied. May be {@code null}.
411411
* @see DisposableSqlTypeValue#cleanup()
412412
* @see org.springframework.jdbc.core.support.SqlLobValue#cleanup()
413413
*/

0 commit comments

Comments
 (0)