apache/shardingsphere · error · SQLFeatureNotSupportedException

getObject with type, cannot convert %s:%s to %s

Error message

getObject with type, cannot convert %s:%s to %s

What it means

Error "getObject with type, cannot convert %s:%s to %s" thrown in apache/shardingsphere.

Source

Thrown at infra/executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/result/query/impl/driver/jdbc/type/util/ResultSetUtils.java:112

        if (value instanceof byte[]) {
            return convertByteArrayValue((byte[]) value, convertType);
        }
        if (String.class.equals(convertType)) {
            return value.toString();
        }
        if (value instanceof String) {
            Optional<Object> result = convertStringValue((String) value, convertType);
            if (result.isPresent()) {
                return result.get();
            }
        }
        if (boolean.class.equals(convertType)) {
            return convertBooleanValue(value);
        }
        try {
            return convertType.cast(value);
        } catch (final ClassCastException ignored) {
            throw new SQLFeatureNotSupportedException("getObject with type, cannot convert " + value.getClass().getName() + ":" + value + " to " + convertType.getName());
        }
    }
    
    private static Optional<Object> convertStringValue(final String value, final Class<?> convertType) {
        if (byte[].class.equals(convertType)) {
            return Optional.of(value.getBytes(StandardCharsets.UTF_8));
        }
        if (Timestamp.class.equals(convertType)) {
            TemporalAccessor temporalAccessor = LOOSE_DATE_TIME_FORMATTER.parseBest(value, LocalDateTime::from, LocalDate::from);
            LocalDateTime localDateTime = (temporalAccessor instanceof LocalDateTime) ? (LocalDateTime) temporalAccessor : ((LocalDate) temporalAccessor).atStartOfDay();
            return Optional.of(Timestamp.valueOf(localDateTime));
        }
        if (java.sql.Date.class.equals(convertType)) {
            return Optional.of(java.sql.Date.valueOf(LocalDate.from(LOOSE_DATE_TIME_FORMATTER.parse(value))));
        }
        if (Time.class.equals(convertType)) {
            return Optional.of(Time.valueOf(LocalTime.from(LOOSE_DATE_TIME_FORMATTER.parse(value))));
        }

View on GitHub (pinned to e952770a21)

Solutions

  1. Call getObject with a Java type compatible with the column's SQL type.
  2. Use the driver-specific conversion (e.g. getString, getTimestamp) appropriate for the column.
  3. Check the database type of the column and map it to a supported Java type.

When it happens

Trigger: ResultSetUtils.getObject with an explicit type cannot convert the column value to the requested Java type.

Common situations: Requesting a Java type with no defined mapping from the column's JDBC type, e.g. converting a numeric column to a struct type.


AI-assisted analysis of apache/shardingsphere@e952770a21 (2026-08-14). Data as JSON: /api/errors/36e69f15ef745b8b. Report an issue: GitHub.