@@ -68,13 +68,16 @@ public abstract class StatementCreatorUtils {
68
68
* System property that instructs Spring to ignore {@link java.sql.ParameterMetaData#getParameterType}
69
69
* completely, i.e. to never even attempt to retrieve {@link PreparedStatement#getParameterMetaData()}
70
70
* for {@link StatementCreatorUtils#setNull} calls.
71
- * <p>The default is "false", trying {@code getParameterType} calls first and falling back to
71
+ * <p>The effective default is "false", trying {@code getParameterType} calls first and falling back to
72
72
* {@link PreparedStatement#setNull} / {@link PreparedStatement#setObject} calls based on well-known
73
73
* behavior of common databases. Spring records JDBC drivers with non-working {@code getParameterType}
74
74
* implementations and won't attempt to call that method for that driver again, always falling back.
75
75
* <p>Consider switching this flag to "true" if you experience misbehavior at runtime, e.g. with
76
76
* a connection pool setting back the {@link PreparedStatement} instance in case of an exception
77
77
* thrown from {@code getParameterType} (as reported on JBoss AS 7).
78
+ * <p>Note that this flag is "true" by default on Oracle 12c since there can be leaks created by
79
+ * {@code getParameterType} calls in such a scenario. You need to explicitly set the flag to
80
+ * "false" in order to enforce the use of {@code getParameterType} against Oracle drivers.
78
81
*/
79
82
public static final String IGNORE_GETPARAMETERTYPE_PROPERTY_NAME = "spring.jdbc.getParameterType.ignore" ;
80
83
@@ -339,10 +342,12 @@ private static void setValue(PreparedStatement ps, int paramIndex, int sqlType,
339
342
else if (inValue instanceof SqlValue ) {
340
343
((SqlValue ) inValue ).setValue (ps , paramIndex );
341
344
}
342
- else if (sqlType == Types .VARCHAR || sqlType == Types .NVARCHAR ||
343
- sqlType == Types .LONGVARCHAR || sqlType == Types .LONGNVARCHAR ) {
345
+ else if (sqlType == Types .VARCHAR || sqlType == Types .LONGVARCHAR ) {
344
346
ps .setString (paramIndex , inValue .toString ());
345
347
}
348
+ else if (sqlType == Types .NVARCHAR || sqlType == Types .LONGNVARCHAR ) {
349
+ ps .setNString (paramIndex , inValue .toString ());
350
+ }
346
351
else if ((sqlType == Types .CLOB || sqlType == Types .NCLOB ) && isStringValue (inValue .getClass ())) {
347
352
String strVal = inValue .toString ();
348
353
if (strVal .length () > 4000 ) {
@@ -364,8 +369,13 @@ else if ((sqlType == Types.CLOB || sqlType == Types.NCLOB) && isStringValue(inVa
364
369
logger .debug ("JDBC driver does not support JDBC 4.0 'setClob(int, Reader, long)' method" , ex );
365
370
}
366
371
}
367
- // Fallback: regular setString binding
368
- ps .setString (paramIndex , strVal );
372
+ // Fallback: setString or setNString binding
373
+ if (sqlType == Types .NCLOB ) {
374
+ ps .setNString (paramIndex , strVal );
375
+ }
376
+ else {
377
+ ps .setString (paramIndex , strVal );
378
+ }
369
379
}
370
380
else if (sqlType == Types .DECIMAL || sqlType == Types .NUMERIC ) {
371
381
if (inValue instanceof BigDecimal ) {
0 commit comments