Skip to content

Commit 6b4c29c

Browse files
committed
Defensively uses JDBC 3.0 getParameterType call for Oracle driver compatibility
Issue: SPR-10385
1 parent ff6d7a8 commit 6b4c29c

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

spring-jdbc/src/main/java/org/springframework/jdbc/core/StatementCreatorUtils.java

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import java.sql.Blob;
2323
import java.sql.Clob;
2424
import java.sql.DatabaseMetaData;
25-
import java.sql.ParameterMetaData;
2625
import java.sql.PreparedStatement;
2726
import java.sql.SQLException;
2827
import java.sql.Types;
@@ -229,18 +228,13 @@ private static void setNull(PreparedStatement ps, int paramIndex, int sqlType, S
229228
boolean useSetObject = false;
230229
sqlType = Types.NULL;
231230
try {
232-
ParameterMetaData pmd = null;
231+
sqlType = ps.getParameterMetaData().getParameterType(paramIndex);
232+
}
233+
catch (Throwable ex) {
234+
logger.debug("JDBC 3.0 getParameterType call not supported", ex);
235+
// JDBC driver not compliant with JDBC 3.0
236+
// -> proceed with database-specific checks
233237
try {
234-
pmd = ps.getParameterMetaData();
235-
}
236-
catch (Throwable ex) {
237-
// JDBC driver not compliant with JDBC 3.0
238-
// -> proceed with database-specific checks
239-
}
240-
if (pmd != null) {
241-
sqlType = pmd.getParameterType(paramIndex);
242-
}
243-
else {
244238
DatabaseMetaData dbmd = ps.getConnection().getMetaData();
245239
String databaseProductName = dbmd.getDatabaseProductName();
246240
String jdbcDriverName = dbmd.getDriverName();
@@ -255,9 +249,9 @@ else if (databaseProductName.startsWith("DB2") ||
255249
sqlType = Types.VARCHAR;
256250
}
257251
}
258-
}
259-
catch (Throwable ex) {
260-
logger.debug("Could not check database or driver name", ex);
252+
catch (Throwable ex2) {
253+
logger.debug("Could not check database or driver name", ex2);
254+
}
261255
}
262256
if (useSetObject) {
263257
ps.setObject(paramIndex, null);

0 commit comments

Comments
 (0)