@@ -81,12 +81,13 @@ public abstract class StatementCreatorUtils {
81
81
public static final String IGNORE_GETPARAMETERTYPE_PROPERTY_NAME = "spring.jdbc.getParameterType.ignore" ;
82
82
83
83
84
- static boolean shouldIgnoreGetParameterType = SpringProperties .getFlag (IGNORE_GETPARAMETERTYPE_PROPERTY_NAME );
85
-
86
84
private static final Log logger = LogFactory .getLog (StatementCreatorUtils .class );
87
85
88
86
private static final Map <Class <?>, Integer > javaTypeToSqlTypeMap = new HashMap <>(64 );
89
87
88
+ @ Nullable
89
+ static Boolean shouldIgnoreGetParameterType ;
90
+
90
91
static {
91
92
javaTypeToSqlTypeMap .put (boolean .class , Types .BOOLEAN );
92
93
javaTypeToSqlTypeMap .put (Boolean .class , Types .BOOLEAN );
@@ -114,6 +115,11 @@ public abstract class StatementCreatorUtils {
114
115
javaTypeToSqlTypeMap .put (java .sql .Timestamp .class , Types .TIMESTAMP );
115
116
javaTypeToSqlTypeMap .put (Blob .class , Types .BLOB );
116
117
javaTypeToSqlTypeMap .put (Clob .class , Types .CLOB );
118
+
119
+ String flag = SpringProperties .getProperty (IGNORE_GETPARAMETERTYPE_PROPERTY_NAME );
120
+ if (flag != null ) {
121
+ shouldIgnoreGetParameterType = Boolean .valueOf (flag );
122
+ }
117
123
}
118
124
119
125
@@ -250,9 +256,26 @@ private static void setNull(PreparedStatement ps, int paramIndex, int sqlType, @
250
256
throws SQLException {
251
257
252
258
if (sqlType == SqlTypeValue .TYPE_UNKNOWN || (sqlType == Types .OTHER && typeName == null )) {
259
+ boolean callGetParameterType = false ;
253
260
boolean useSetObject = false ;
254
261
Integer sqlTypeToUse = null ;
255
- if (!shouldIgnoreGetParameterType ) {
262
+ if (shouldIgnoreGetParameterType != null ) {
263
+ callGetParameterType = !shouldIgnoreGetParameterType ;
264
+ }
265
+ else {
266
+ String jdbcDriverName = ps .getConnection ().getMetaData ().getDriverName ();
267
+ if (jdbcDriverName .startsWith ("PostgreSQL" )) {
268
+ sqlTypeToUse = Types .NULL ;
269
+ }
270
+ else if (jdbcDriverName .startsWith ("Microsoft" ) && jdbcDriverName .contains ("SQL Server" )) {
271
+ sqlTypeToUse = Types .NULL ;
272
+ useSetObject = true ;
273
+ }
274
+ else {
275
+ callGetParameterType = true ;
276
+ }
277
+ }
278
+ if (callGetParameterType ) {
256
279
try {
257
280
sqlTypeToUse = ps .getParameterMetaData ().getParameterType (paramIndex );
258
281
}
0 commit comments