Skip to content

Commit 050e581

Browse files
committed
StatementCreatorUtils.setValue only uses setString etc for Types.OTHER in case of Oracle
Issue: SPR-12890
1 parent 10a51a4 commit 050e581

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,8 @@ else if (inValue instanceof Calendar) {
410410
ps.setObject(paramIndex, inValue, Types.TIMESTAMP);
411411
}
412412
}
413-
else if (sqlType == SqlTypeValue.TYPE_UNKNOWN || sqlType == Types.OTHER) {
413+
else if (sqlType == SqlTypeValue.TYPE_UNKNOWN || (sqlType == Types.OTHER &&
414+
"Oracle".equals(ps.getConnection().getMetaData().getDatabaseProductName()))) {
414415
if (isStringValue(inValue.getClass())) {
415416
ps.setString(paramIndex, inValue.toString());
416417
}

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

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2015 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.
@@ -38,11 +38,13 @@ public class StatementCreatorUtilsTests {
3838

3939
private PreparedStatement preparedStatement;
4040

41+
4142
@Before
4243
public void setUp() {
4344
preparedStatement = mock(PreparedStatement.class);
4445
}
4546

47+
4648
@Test
4749
public void testSetParameterValueWithNullAndType() throws SQLException {
4850
StatementCreatorUtils.setParameterValue(preparedStatement, 1, Types.VARCHAR, null, null);
@@ -264,9 +266,15 @@ public void testSetParameterValueWithCalendarAndUnknownType() throws SQLExceptio
264266

265267
@Test // SPR-8571
266268
public void testSetParameterValueWithStringAndVendorSpecificType() throws SQLException {
269+
Connection con = mock(Connection.class);
270+
DatabaseMetaData dbmd = mock(DatabaseMetaData.class);
271+
given(preparedStatement.getConnection()).willReturn(con);
272+
given(dbmd.getDatabaseProductName()).willReturn("Oracle");
273+
given(con.getMetaData()).willReturn(dbmd);
267274
StatementCreatorUtils.setParameterValue(preparedStatement, 1, Types.OTHER, null, "test");
268275
verify(preparedStatement).setString(1, "test");
269276
}
277+
270278
@Test // SPR-8571
271279
public void testSetParameterValueWithNullAndVendorSpecificType() throws SQLException {
272280
StatementCreatorUtils.setParameterValue(preparedStatement, 1, Types.OTHER, null, null);

0 commit comments

Comments
 (0)