Skip to content

added database-specific data type condition check #628

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import org.springframework.core.SpringProperties;
import org.springframework.jdbc.support.SqlValue;

Expand Down Expand Up @@ -239,7 +238,7 @@ private static void setParameterValueInternal(PreparedStatement ps, int paramInd
* 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;
Expand Down Expand Up @@ -385,7 +384,7 @@ else if (inValue instanceof Calendar) {
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());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -262,4 +262,15 @@ public void testSetParameterValueWithCalendarAndUnknownType() throws SQLExceptio
verify(preparedStatement).setTimestamp(1, new java.sql.Timestamp(cal.getTime().getTime()), cal);
}

@Test
public void testSetParameterValueWithStringAndVenderSpecificTypeSpr8571() throws SQLException {
StatementCreatorUtils.setParameterValue(preparedStatement, 1, Types.OTHER, null, "test");
verify(preparedStatement).setString(1, "test");
}

@Test
public void testSetParameterValueWithNullAndVenderSpecificTypeSpr8571() throws SQLException {
StatementCreatorUtils.setParameterValue(preparedStatement, 1, Types.OTHER, null, null);
verify(preparedStatement).setNull(1, Types.NULL);
}
}