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 1e4439e11b..a28072ffb1 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 @@ -239,7 +239,7 @@ public abstract class StatementCreatorUtils { * 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 +385,7 @@ public abstract class StatementCreatorUtils { 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 88f1e51047..38641498ac 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 class StatementCreatorUtilsTests { verify(preparedStatement).setTimestamp(1, new java.sql.Timestamp(cal.getTime().getTime()), cal); } + @Test // SPR-8571 + public void testSetParameterValueWithStringAndVendorSpecificType() throws SQLException { + StatementCreatorUtils.setParameterValue(preparedStatement, 1, Types.OTHER, null, "test"); + verify(preparedStatement).setString(1, "test"); + } + @Test // SPR-8571 + public void testSetParameterValueWithNullAndVendorSpecificType() throws SQLException { + StatementCreatorUtils.setParameterValue(preparedStatement, 1, Types.OTHER, null, null); + verify(preparedStatement).setNull(1, Types.NULL); + } + }