prestodb/presto · error · SQLException

Unsupported object type:

Error message

Unsupported object type: 

What it means

PrestoPreparedStatement.setObject only supports a fixed set of Java types (String, Boolean, numeric types, byte[], Date, Time, Timestamp, etc.). If the passed object's runtime type is not one of those, it throws a SQLException naming the actual class. Presto's JDBC driver has a narrow parameter type mapping, so arbitrary Java objects cannot be bound.

Source

Thrown at presto-jdbc/src/main/java/com/facebook/presto/jdbc/PrestoPreparedStatement.java:433

            setBigDecimal(parameterIndex, (BigDecimal) x);
        }
        else if (x instanceof String) {
            setString(parameterIndex, (String) x);
        }
        else if (x instanceof byte[]) {
            setBytes(parameterIndex, (byte[]) x);
        }
        else if (x instanceof Date) {
            setDate(parameterIndex, (Date) x);
        }
        else if (x instanceof Time) {
            setTime(parameterIndex, (Time) x);
        }
        else if (x instanceof Timestamp) {
            setTimestamp(parameterIndex, (Timestamp) x);
        }
        else {
            throw new SQLException("Unsupported object type: " + x.getClass().getName());
        }
    }

    @Override
    public void addBatch()
            throws SQLException
    {
        checkOpen();
        batchValues.add(toValues(parameters));
        isBatch = true;
    }

    @Override
    public void clearBatch()
            throws SQLException
    {
        checkOpen();
        batchValues.clear();

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Convert the value to a supported JDBC type before calling setObject (e.g. Date.from(localDate), Timestamp.valueOf(localDateTime), uuid.toString()).
  2. Use the type-specific setter: setString for text/UUID, setLong/setInt for numbers, setTimestamp for instants.
  3. Pass null via setNull(i, Types.X) when the value is null of unknown type.
  4. Check the driver version; newer Presto/Trino JDBC drivers may accept java.time types via setObject.

Example fix

// before
UUID id = UUID.randomUUID();
ps.setObject(1, id);
// after
ps.setString(1, id.toString());
Defensive patterns

Strategy: type-guard

Validate before calling

private static final Set<Class<?>> SUPPORTED = Set.of(String.class, Boolean.class, Integer.class, Long.class, Short.class, Byte.class, Double.class, Float.class, byte[].class, java.math.BigDecimal.class, java.sql.Date.class, java.sql.Time.class, java.sql.Timestamp.class);
if (x != null && !SUPPORTED.contains(x.getClass())) throw new IllegalArgumentException("convert type before setObject: " + x.getClass());

Type guard

static boolean isSupportedParam(Object x) {
    return x == null || x instanceof String || x instanceof Boolean || x instanceof Number
        || x instanceof byte[] || x instanceof java.sql.Date || x instanceof java.sql.Time
        || x instanceof java.sql.Timestamp || x instanceof java.math.BigDecimal;
}

Try / catch

try { ps.setObject(i, x); } catch (SQLException e) { if (e.getMessage().startsWith("Unsupported object type")) { ps.setString(i, String.valueOf(x)); } else throw e; }

Prevention

When it happens

Trigger: Calling setObject(i, x) with an unsupported type such as BigDecimal? (supported), UUID, LocalDate, LocalDateTime, enum, or any custom POJO — any object not instanceof String, Boolean, Integer, Long, Double, Float, Short, Byte, byte[], BigDecimal, Date, Time, or Timestamp.

Common situations: Migrating code from drivers that support JDBC 4.2 java.time types (LocalDate/LocalDateTime) or ORM-generated parameter objects; passing UUID or enum values directly instead of converting them.

Related errors


AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04). Data as JSON: /api/errors/4108585b7dc9de24. Report an issue: GitHub.