prestodb/presto · error · SQLFeatureNotSupportedException

setCharacterStream

Error message

setCharacterStream

What it means

The length-less PreparedStatement.setCharacterStream(int, Reader) is unsupported in Presto's JDBC driver and throws SQLFeatureNotSupportedException. Character streaming is intentionally unimplemented; callers must provide text as a String.

Source

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

    @Override
    public void setAsciiStream(int parameterIndex, InputStream x)
            throws SQLException
    {
        throw new SQLFeatureNotSupportedException("setAsciiStream");
    }

    @Override
    public void setBinaryStream(int parameterIndex, InputStream x)
            throws SQLException
    {
        throw new SQLFeatureNotSupportedException("setBinaryStream");
    }

    @Override
    public void setCharacterStream(int parameterIndex, Reader reader)
            throws SQLException
    {
        throw new SQLFeatureNotSupportedException("setCharacterStream");
    }

    @Override
    public void setNCharacterStream(int parameterIndex, Reader value)
            throws SQLException
    {
        throw new SQLFeatureNotSupportedException("setNCharacterStream");
    }

    @Override
    public void setClob(int parameterIndex, Reader reader)
            throws SQLException
    {
        throw new SQLFeatureNotSupportedException("setClob");
    }

    @Override
    public void setBlob(int parameterIndex, InputStream inputStream)

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Read the Reader into a String and call setString(parameterIndex, value)
  2. Use setObject with the String
  3. Buffer the reader content via CharStreams.toString / Stream copy then setString
  4. Avoid Reader-typed parameters entirely with this driver

Example fix

// before
ps.setCharacterStream(1, reader);
// after
StringBuilder sb = new StringBuilder();
char[] buf = new char[8192];
int n;
while ((n = reader.read(buf)) > 0) sb.append(buf, 0, n);
ps.setString(1, sb.toString());
Defensive patterns

Strategy: try-catch

Validate before calling

if (value instanceof Reader) {
    throw new IllegalStateException("Presto JDBC does not support setCharacterStream; use setString");
}

Type guard

boolean isSupportedParamType(Object v) {
    return v instanceof String || v instanceof Number || v instanceof Boolean
        || v instanceof byte[] || v instanceof java.sql.Date
        || v instanceof java.sql.Time || v instanceof java.sql.Timestamp;
}

Try / catch

try {
    ps.setCharacterStream(idx, reader);
} catch (SQLFeatureNotSupportedException e) {
    ps.setString(idx, CharStreams.toString(reader));
}

Prevention

When it happens

Trigger: Calling PreparedStatement.setCharacterStream(parameterIndex, reader) on a PrestoPreparedStatement.

Common situations: JDBC 4 style code omitting length; ORMs detecting Reader parameters and choosing the stream setter.

Related errors


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