From e4c5b77de79fa8b5ea71891c7c7223d12f42a35b Mon Sep 17 00:00:00 2001 From: jmaxwell Date: Fri, 3 Nov 2017 14:49:32 -0500 Subject: [PATCH] SPR-16154 - Correctly handle NVARCHAR, LONGNVARCHAR and NCLOBs --- .../jdbc/core/StatementCreatorUtils.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) 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 62c990e284..303a8fc766 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 @@ -295,10 +295,12 @@ public abstract class StatementCreatorUtils { else if (inValue instanceof SqlValue) { ((SqlValue) inValue).setValue(ps, paramIndex); } - else if (sqlType == Types.VARCHAR || sqlType == Types.NVARCHAR || - sqlType == Types.LONGVARCHAR || sqlType == Types.LONGNVARCHAR) { + else if (sqlType == Types.VARCHAR || sqlType == Types.LONGVARCHAR ) { ps.setString(paramIndex, inValue.toString()); } + else if (sqlType == Types.NVARCHAR || sqlType == Types.LONGNVARCHAR) { + ps.setNString(paramIndex, inValue.toString()); + } else if ((sqlType == Types.CLOB || sqlType == Types.NCLOB) && isStringValue(inValue.getClass())) { String strVal = inValue.toString(); if (strVal.length() > 4000) { @@ -312,8 +314,15 @@ public abstract class StatementCreatorUtils { } return; } - // Fallback: regular setString binding - ps.setString(paramIndex, strVal); + else { + // Fallback: setString or setNString binding + if (sqlType == Types.NCLOB) { + ps.setNString(paramIndex, strVal); + } + else { + ps.setString(paramIndex, strVal); + } + } } else if (sqlType == Types.DECIMAL || sqlType == Types.NUMERIC) { if (inValue instanceof BigDecimal) {