diff --git a/org.springframework.jdbc/src/main/java/org/springframework/jdbc/core/PreparedStatementCreatorFactory.java b/org.springframework.jdbc/src/main/java/org/springframework/jdbc/core/PreparedStatementCreatorFactory.java index 192a9a267b..c4f72c55b0 100644 --- a/org.springframework.jdbc/src/main/java/org/springframework/jdbc/core/PreparedStatementCreatorFactory.java +++ b/org.springframework.jdbc/src/main/java/org/springframework/jdbc/core/PreparedStatementCreatorFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2012 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -235,10 +235,10 @@ public class PreparedStatementCreatorFactory { ps = con.prepareStatement(this.actualSql, PreparedStatement.RETURN_GENERATED_KEYS); } } - catch (AbstractMethodError ex) { + catch (AbstractMethodError err) { throw new InvalidDataAccessResourceUsageException( - "The JDBC driver is not compliant to JDBC 3.0 and thus " + - "does not support retrieval of auto-generated keys", ex); + "Your JDBC driver is not compliant with JDBC 3.0 - " + + "it does not support retrieval of auto-generated keys", err); } } else if (resultSetType == ResultSet.TYPE_FORWARD_ONLY && !updatableResults) { diff --git a/org.springframework.jdbc/src/main/java/org/springframework/jdbc/core/StatementCreatorUtils.java b/org.springframework.jdbc/src/main/java/org/springframework/jdbc/core/StatementCreatorUtils.java index 19b1b67243..2bb0ade6d1 100644 --- a/org.springframework.jdbc/src/main/java/org/springframework/jdbc/core/StatementCreatorUtils.java +++ b/org.springframework.jdbc/src/main/java/org/springframework/jdbc/core/StatementCreatorUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2009 the original author or authors. + * Copyright 2002-2012 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,6 +22,7 @@ import java.math.BigInteger; import java.sql.Blob; import java.sql.Clob; import java.sql.DatabaseMetaData; +import java.sql.ParameterMetaData; import java.sql.PreparedStatement; import java.sql.SQLException; import java.sql.Types; @@ -189,7 +190,7 @@ public abstract class StatementCreatorUtils { if (inValue instanceof SqlParameterValue) { SqlParameterValue parameterValue = (SqlParameterValue) inValue; if (logger.isDebugEnabled()) { - logger.debug("Overriding typeinfo with runtime info from SqlParameterValue: column index " + paramIndex + + logger.debug("Overriding type info with runtime info from SqlParameterValue: column index " + paramIndex + ", SQL type " + parameterValue.getSqlType() + ", Type name " + parameterValue.getTypeName()); } @@ -228,18 +229,31 @@ public abstract class StatementCreatorUtils { boolean useSetObject = false; sqlType = Types.NULL; try { - DatabaseMetaData dbmd = ps.getConnection().getMetaData(); - String databaseProductName = dbmd.getDatabaseProductName(); - String jdbcDriverName = dbmd.getDriverName(); - if (databaseProductName.startsWith("Informix") || - jdbcDriverName.startsWith("Microsoft SQL Server")) { - useSetObject = true; + ParameterMetaData pmd = null; + try { + pmd = ps.getParameterMetaData(); } - else if (databaseProductName.startsWith("DB2") || - jdbcDriverName.startsWith("jConnect") || - jdbcDriverName.startsWith("SQLServer")|| - jdbcDriverName.startsWith("Apache Derby")) { - sqlType = Types.VARCHAR; + catch (AbstractMethodError err) { + // JDBC driver not compliant with JDBC 3.0 + // -> proceed with database-specific checks + } + if (pmd != null) { + sqlType = pmd.getParameterType(paramIndex); + } + else { + DatabaseMetaData dbmd = ps.getConnection().getMetaData(); + String databaseProductName = dbmd.getDatabaseProductName(); + String jdbcDriverName = dbmd.getDriverName(); + if (databaseProductName.startsWith("Informix") || + jdbcDriverName.startsWith("Microsoft SQL Server")) { + useSetObject = true; + } + else if (databaseProductName.startsWith("DB2") || + jdbcDriverName.startsWith("jConnect") || + jdbcDriverName.startsWith("SQLServer")|| + jdbcDriverName.startsWith("Apache Derby")) { + sqlType = Types.VARCHAR; + } } } catch (Throwable ex) {