private static void logColumnLengthError (SQLServerBulkCopy bulkCopy, SQLException ex) {
      if (ex.getMessage().contains("Received an invalid column length from the bcp client for colid")) {
         try {
            String pattern = "\\d+";
            Pattern r = Pattern.compile(pattern);
            Matcher m = r.matcher(ex.getMessage());
            if (m.find()) {
               // get source column metadata
               Field fi = SQLServerBulkCopy.class.getDeclaredField("srcColumnMetadata");
               fi.setAccessible(true);
               HashMap<Integer, Object> srcColumnsMetadata = (HashMap<Integer, Object>) fi.get(bulkCopy);
               // get destination column metadata
               fi = SQLServerBulkCopy.class.getDeclaredField("destColumnMetadata");
               fi.setAccessible(true);
               HashMap<Integer, Object> destColumnsMetadata = (HashMap<Integer, Object>) fi.get(bulkCopy);

               // iterate over the HashMap and log the columns metadata and mapping
               for (Integer key : destColumnsMetadata.keySet()) {

                  // get source column metadata
                  Object srcColumnMetadata = srcColumnsMetadata.get(key);
                  // get source column name
                  fi = srcColumnMetadata.getClass().getDeclaredField("columnName");
                  fi.setAccessible(true);
                  String srcColumnName = (String) fi.get(srcColumnMetadata);
                  // get source column precision
                  fi = srcColumnMetadata.getClass().getDeclaredField("precision");
                  fi.setAccessible(true);
                  int srcColumnPrecision = (int) fi.get(srcColumnMetadata);
                  // get source column scale
                  fi = srcColumnMetadata.getClass().getDeclaredField("scale");
                  fi.setAccessible(true);
                  int srcColumnScale = (int) fi.get(srcColumnMetadata);
                  // get source column type
                  fi = srcColumnMetadata.getClass().getDeclaredField("jdbcType");
                  fi.setAccessible(true);
                  int srcColumnType = (int) fi.get(srcColumnMetadata);
                  String srcType = getJdbcTypeName(srcColumnType);


                  // get destination column metadata
                  Object destColumnMeta = destColumnsMetadata.get(key);
                  // get the column Name
                  fi = destColumnMeta.getClass().getDeclaredField("columnName");
                  fi.setAccessible(true);
                  String destColumnName = (String) fi.get(destColumnMeta);
                  // get the precision
                  fi = destColumnMeta.getClass().getDeclaredField("precision");
                  fi.setAccessible(true);
                  int destPrecision = (int) fi.get(destColumnMeta);
                  // get the scale
                  fi = destColumnMeta.getClass().getDeclaredField("scale");
                  fi.setAccessible(true);
                  int destScale = (int) fi.get(destColumnMeta);
                  // get the type
                  fi =  destColumnMeta.getClass().getDeclaredField("jdbcType");
                  fi.setAccessible(true);
                  int destJdbcType = (int) fi.get(destColumnMeta);
                  // convert to string the type
                  String destType = "";
                  destType = getJdbcTypeName(destJdbcType);

                  // Log source column mapped to sink column with metadata
                  LOG.debug("colid {} : Source column {} ({}:(precision:{},scale:{})) mapped to sink column {} ({}:(precision:{},scale:{}))", key, srcColumnName, srcType, srcColumnPrecision, srcColumnScale, destColumnName, destType, destPrecision, destScale);

               }
            }
         } catch (NoSuchFieldException | IllegalAccessException e) {
            // ignore exception
         }
      }
   }
Log the error message and the column name and length that caused the error using reflection.

@param bulkCopy the SQLServerBulkCopy object
@param ex       the SQLException
src/main/java/org/replicadb/manager/SQLServerManager.java