|
1 | 1 | /* |
2 | | - * Copyright 2002-2012 the original author or authors. |
| 2 | + * Copyright 2002-2013 the original author or authors. |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
|
22 | 22 | import java.sql.Blob; |
23 | 23 | import java.sql.Clob; |
24 | 24 | import java.sql.DatabaseMetaData; |
| 25 | +import java.sql.ParameterMetaData; |
25 | 26 | import java.sql.PreparedStatement; |
26 | 27 | import java.sql.SQLException; |
27 | 28 | import java.sql.Types; |
@@ -189,7 +190,7 @@ private static void setParameterValueInternal( |
189 | 190 | if (inValue instanceof SqlParameterValue) { |
190 | 191 | SqlParameterValue parameterValue = (SqlParameterValue) inValue; |
191 | 192 | if (logger.isDebugEnabled()) { |
192 | | - logger.debug("Overriding typeinfo with runtime info from SqlParameterValue: column index " + paramIndex + |
| 193 | + logger.debug("Overriding type info with runtime info from SqlParameterValue: column index " + paramIndex + |
193 | 194 | ", SQL type " + parameterValue.getSqlType() + |
194 | 195 | ", Type name " + parameterValue.getTypeName()); |
195 | 196 | } |
@@ -228,18 +229,31 @@ private static void setNull(PreparedStatement ps, int paramIndex, int sqlType, S |
228 | 229 | boolean useSetObject = false; |
229 | 230 | sqlType = Types.NULL; |
230 | 231 | try { |
231 | | - DatabaseMetaData dbmd = ps.getConnection().getMetaData(); |
232 | | - String databaseProductName = dbmd.getDatabaseProductName(); |
233 | | - String jdbcDriverName = dbmd.getDriverName(); |
234 | | - if (databaseProductName.startsWith("Informix") || |
235 | | - jdbcDriverName.startsWith("Microsoft SQL Server")) { |
236 | | - useSetObject = true; |
| 232 | + ParameterMetaData pmd = null; |
| 233 | + try { |
| 234 | + pmd = ps.getParameterMetaData(); |
237 | 235 | } |
238 | | - else if (databaseProductName.startsWith("DB2") || |
239 | | - jdbcDriverName.startsWith("jConnect") || |
240 | | - jdbcDriverName.startsWith("SQLServer")|| |
241 | | - jdbcDriverName.startsWith("Apache Derby")) { |
242 | | - sqlType = Types.VARCHAR; |
| 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 { |
| 244 | + DatabaseMetaData dbmd = ps.getConnection().getMetaData(); |
| 245 | + String databaseProductName = dbmd.getDatabaseProductName(); |
| 246 | + String jdbcDriverName = dbmd.getDriverName(); |
| 247 | + if (databaseProductName.startsWith("Informix") || |
| 248 | + jdbcDriverName.startsWith("Microsoft SQL Server")) { |
| 249 | + useSetObject = true; |
| 250 | + } |
| 251 | + else if (databaseProductName.startsWith("DB2") || |
| 252 | + jdbcDriverName.startsWith("jConnect") || |
| 253 | + jdbcDriverName.startsWith("SQLServer")|| |
| 254 | + jdbcDriverName.startsWith("Apache Derby")) { |
| 255 | + sqlType = Types.VARCHAR; |
| 256 | + } |
243 | 257 | } |
244 | 258 | } |
245 | 259 | catch (Throwable ex) { |
|
0 commit comments