Skip to content

Commit 759f430

Browse files
committed
StatementCreatorUtils avoids direct calls with SQL type argument in case of Types.OTHER
Issue: SPR-8571
1 parent 8c76381 commit 759f430

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ private static void setParameterValueInternal(PreparedStatement ps, int paramInd
239239
* respecting database-specific peculiarities.
240240
*/
241241
private static void setNull(PreparedStatement ps, int paramIndex, int sqlType, String typeName) throws SQLException {
242-
if (sqlType == SqlTypeValue.TYPE_UNKNOWN) {
242+
if (sqlType == SqlTypeValue.TYPE_UNKNOWN || sqlType == Types.OTHER) {
243243
boolean useSetObject = false;
244244
Integer sqlTypeToUse = null;
245245
DatabaseMetaData dbmd = null;
@@ -385,7 +385,7 @@ else if (inValue instanceof Calendar) {
385385
ps.setObject(paramIndex, inValue, Types.TIMESTAMP);
386386
}
387387
}
388-
else if (sqlType == SqlTypeValue.TYPE_UNKNOWN) {
388+
else if (sqlType == SqlTypeValue.TYPE_UNKNOWN || sqlType == Types.OTHER) {
389389
if (isStringValue(inValue.getClass())) {
390390
ps.setString(paramIndex, inValue.toString());
391391
}

spring-jdbc/src/test/java/org/springframework/jdbc/core/StatementCreatorUtilsTests.java

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2014 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.
@@ -262,4 +262,15 @@ public void testSetParameterValueWithCalendarAndUnknownType() throws SQLExceptio
262262
verify(preparedStatement).setTimestamp(1, new java.sql.Timestamp(cal.getTime().getTime()), cal);
263263
}
264264

265+
@Test // SPR-8571
266+
public void testSetParameterValueWithStringAndVendorSpecificType() throws SQLException {
267+
StatementCreatorUtils.setParameterValue(preparedStatement, 1, Types.OTHER, null, "test");
268+
verify(preparedStatement).setString(1, "test");
269+
}
270+
@Test // SPR-8571
271+
public void testSetParameterValueWithNullAndVendorSpecificType() throws SQLException {
272+
StatementCreatorUtils.setParameterValue(preparedStatement, 1, Types.OTHER, null, null);
273+
verify(preparedStatement).setNull(1, Types.NULL);
274+
}
275+
265276
}

0 commit comments

Comments
 (0)