diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/StatementCreatorUtils.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/StatementCreatorUtils.java index 1e4439e11b3b..babceb9698b4 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/StatementCreatorUtils.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/StatementCreatorUtils.java @@ -36,7 +36,6 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; - import org.springframework.core.SpringProperties; import org.springframework.jdbc.support.SqlValue; @@ -239,7 +238,7 @@ private static void setParameterValueInternal(PreparedStatement ps, int paramInd * respecting database-specific peculiarities. */ private static void setNull(PreparedStatement ps, int paramIndex, int sqlType, String typeName) throws SQLException { - if (sqlType == SqlTypeValue.TYPE_UNKNOWN) { + if (sqlType == SqlTypeValue.TYPE_UNKNOWN || sqlType == Types.OTHER) { boolean useSetObject = false; Integer sqlTypeToUse = null; DatabaseMetaData dbmd = null; @@ -385,7 +384,7 @@ else if (inValue instanceof Calendar) { ps.setObject(paramIndex, inValue, Types.TIMESTAMP); } } - else if (sqlType == SqlTypeValue.TYPE_UNKNOWN) { + else if (sqlType == SqlTypeValue.TYPE_UNKNOWN || sqlType == Types.OTHER) { if (isStringValue(inValue.getClass())) { ps.setString(paramIndex, inValue.toString()); } diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/core/StatementCreatorUtilsTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/core/StatementCreatorUtilsTests.java index 88f1e51047a6..21a85614adeb 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/core/StatementCreatorUtilsTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/core/StatementCreatorUtilsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -262,4 +262,15 @@ public void testSetParameterValueWithCalendarAndUnknownType() throws SQLExceptio verify(preparedStatement).setTimestamp(1, new java.sql.Timestamp(cal.getTime().getTime()), cal); } + @Test + public void testSetParameterValueWithStringAndVenderSpecificTypeSpr8571() throws SQLException { + StatementCreatorUtils.setParameterValue(preparedStatement, 1, Types.OTHER, null, "test"); + verify(preparedStatement).setString(1, "test"); + } + + @Test + public void testSetParameterValueWithNullAndVenderSpecificTypeSpr8571() throws SQLException { + StatementCreatorUtils.setParameterValue(preparedStatement, 1, Types.OTHER, null, null); + verify(preparedStatement).setNull(1, Types.NULL); + } }