@@ -79,7 +79,7 @@ public abstract class StatementCreatorUtils {
79
79
public static final String IGNORE_GETPARAMETERTYPE_PROPERTY_NAME = "spring.jdbc.getParameterType.ignore" ;
80
80
81
81
82
- static final boolean shouldIgnoreGetParameterType = SpringProperties . getFlag ( IGNORE_GETPARAMETERTYPE_PROPERTY_NAME ) ;
82
+ static final Boolean shouldIgnoreGetParameterType ;
83
83
84
84
static final Set <String > driversWithNoSupportForGetParameterType =
85
85
Collections .newSetFromMap (new ConcurrentHashMap <String , Boolean >(1 ));
@@ -89,6 +89,9 @@ public abstract class StatementCreatorUtils {
89
89
private static final Map <Class <?>, Integer > javaTypeToSqlTypeMap = new HashMap <Class <?>, Integer >(32 );
90
90
91
91
static {
92
+ String propVal = SpringProperties .getProperty (IGNORE_GETPARAMETERTYPE_PROPERTY_NAME );
93
+ shouldIgnoreGetParameterType = (propVal != null ? Boolean .valueOf (propVal ) : null );
94
+
92
95
javaTypeToSqlTypeMap .put (boolean .class , Types .BOOLEAN );
93
96
javaTypeToSqlTypeMap .put (Boolean .class , Types .BOOLEAN );
94
97
javaTypeToSqlTypeMap .put (byte .class , Types .TINYINT );
@@ -246,18 +249,29 @@ private static void setNull(PreparedStatement ps, int paramIndex, int sqlType, S
246
249
Integer sqlTypeToUse = null ;
247
250
DatabaseMetaData dbmd = null ;
248
251
String jdbcDriverName = null ;
249
- boolean checkGetParameterType = !shouldIgnoreGetParameterType ;
250
- if (checkGetParameterType && !driversWithNoSupportForGetParameterType .isEmpty ()) {
252
+ boolean tryGetParameterType = true ;
253
+
254
+ if (shouldIgnoreGetParameterType == null ) {
251
255
try {
252
256
dbmd = ps .getConnection ().getMetaData ();
253
257
jdbcDriverName = dbmd .getDriverName ();
254
- checkGetParameterType = !driversWithNoSupportForGetParameterType .contains (jdbcDriverName );
258
+ tryGetParameterType = !driversWithNoSupportForGetParameterType .contains (jdbcDriverName );
259
+ if (tryGetParameterType && jdbcDriverName .startsWith ("Oracle" )) {
260
+ // Avoid getParameterType use with Oracle 12c driver by default:
261
+ // needs to be explicitly activated through spring.jdbc.getParameterType.ignore=false
262
+ tryGetParameterType = false ;
263
+ driversWithNoSupportForGetParameterType .add (jdbcDriverName );
264
+ }
255
265
}
256
266
catch (Throwable ex ) {
257
267
logger .debug ("Could not check connection metadata" , ex );
258
268
}
259
269
}
260
- if (checkGetParameterType ) {
270
+ else {
271
+ tryGetParameterType = !shouldIgnoreGetParameterType ;
272
+ }
273
+
274
+ if (tryGetParameterType ) {
261
275
try {
262
276
sqlTypeToUse = ps .getParameterMetaData ().getParameterType (paramIndex );
263
277
}
@@ -267,6 +281,7 @@ private static void setNull(PreparedStatement ps, int paramIndex, int sqlType, S
267
281
}
268
282
}
269
283
}
284
+
270
285
if (sqlTypeToUse == null ) {
271
286
// JDBC driver not compliant with JDBC 3.0 -> proceed with database-specific checks
272
287
sqlTypeToUse = Types .NULL ;
@@ -277,8 +292,7 @@ private static void setNull(PreparedStatement ps, int paramIndex, int sqlType, S
277
292
if (jdbcDriverName == null ) {
278
293
jdbcDriverName = dbmd .getDriverName ();
279
294
}
280
- if (checkGetParameterType &&
281
- !(jdbcDriverName .startsWith ("Oracle" ) && dbmd .getDriverMajorVersion () >= 12 )) {
295
+ if (shouldIgnoreGetParameterType == null ) {
282
296
// Register JDBC driver with no support for getParameterType, except for the
283
297
// Oracle 12c driver where getParameterType fails for specific statements only
284
298
// (so an exception thrown above does not indicate general lack of support).
0 commit comments