Browse Source

StatementCreatorUtils.setValue only uses setString etc for Types.OTHER in case of Oracle

Issue: SPR-12890
pull/778/head
Juergen Hoeller 10 years ago
parent
commit
050e581c10
  1. 3
      spring-jdbc/src/main/java/org/springframework/jdbc/core/StatementCreatorUtils.java
  2. 10
      spring-jdbc/src/test/java/org/springframework/jdbc/core/StatementCreatorUtilsTests.java

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

@ -410,7 +410,8 @@ public abstract class StatementCreatorUtils { @@ -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());
}

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

@ -1,5 +1,5 @@ @@ -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 { @@ -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 { @@ -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);

Loading…
Cancel
Save