Handle ClassCastException
@@ -2035,6 +2035,7 @@ public class SQLServerBulkCopy implements java.lang.AutoCloseable {
}
}
+ try {
// We are sending the data using JDBCType and not using SSType as SQL Server will automatically do the conversion.
switch (bulkJdbcType) {
case java.sql.Types.INTEGER:
@@ -2218,9 +2219,9 @@ public class SQLServerBulkCopy implements java.lang.AutoCloseable {
break;
/*
- * The length value associated with these data types is specified within a USHORT. see MS-TDS.pdf page 38. However, nchar(n) nvarchar(n)
- * supports n = 1 .. 4000 (see MSDN SQL 2014, SQL 2016 Transact-SQL) NVARCHAR/NCHAR/LONGNVARCHAR is not compatible with BINARY/VARBINARY
- * as specified in enum UpdaterConversion of DataTypes.java
+ * The length value associated with these data types is specified within a USHORT. see MS-TDS.pdf page 38. However, nchar(n)
+ * nvarchar(n) supports n = 1 .. 4000 (see MSDN SQL 2014, SQL 2016 Transact-SQL) NVARCHAR/NCHAR/LONGNVARCHAR is not compatible with
+ * BINARY/VARBINARY as specified in enum UpdaterConversion of DataTypes.java
*/
case java.sql.Types.LONGNVARCHAR:
case java.sql.Types.NCHAR:
@@ -2447,6 +2448,12 @@ public class SQLServerBulkCopy implements java.lang.AutoCloseable {
SQLServerException.makeFromDriverError(null, null, form.format(msgArgs), null, true);
} // End of switch
}
+ catch (ClassCastException ex) {
+ MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_errorConvertingValue"));
+ Object[] msgArgs = {colValue.getClass().getSimpleName(), JDBCType.of(bulkJdbcType)};
+ throw new SQLServerException(form.format(msgArgs), SQLState.DATA_EXCEPTION_NOT_SPECIFIC, DriverError.NOT_SET, ex);
+ }
+ }
private Object readColumnFromResultSet(int srcColOrdinal,
int srcJdbcType,
