StatementCreatorUtils avoids direct calls with SQL type argument in case of Types.OTHER
Issue: SPR-8571
This commit is contained in:
@@ -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());
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user