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 f760192c99..a96424fcda 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 @@ -410,7 +410,8 @@ public abstract class StatementCreatorUtils { ps.setObject(paramIndex, inValue, Types.TIMESTAMP); } } - else if (sqlType == SqlTypeValue.TYPE_UNKNOWN || sqlType == Types.OTHER) { + else if (sqlType == SqlTypeValue.TYPE_UNKNOWN || (sqlType == Types.OTHER && + "Oracle".equals(ps.getConnection().getMetaData().getDatabaseProductName()))) { 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 38641498ac..1c7cb2e39e 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-2014 the original author or authors. + * Copyright 2002-2015 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. @@ -38,11 +38,13 @@ public class StatementCreatorUtilsTests { private PreparedStatement preparedStatement; + @Before public void setUp() { preparedStatement = mock(PreparedStatement.class); } + @Test public void testSetParameterValueWithNullAndType() throws SQLException { StatementCreatorUtils.setParameterValue(preparedStatement, 1, Types.VARCHAR, null, null); @@ -264,9 +266,15 @@ public class StatementCreatorUtilsTests { @Test // SPR-8571 public void testSetParameterValueWithStringAndVendorSpecificType() throws SQLException { + Connection con = mock(Connection.class); + DatabaseMetaData dbmd = mock(DatabaseMetaData.class); + given(preparedStatement.getConnection()).willReturn(con); + given(dbmd.getDatabaseProductName()).willReturn("Oracle"); + given(con.getMetaData()).willReturn(dbmd); 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);