prestodb/presto · error · SQLFeatureNotSupportedException

setAsciiStream

Error message

setAsciiStream

What it means

The no-length variant PreparedStatement.setAsciiStream(int, InputStream) is unsupported in Presto's JDBC driver and throws SQLFeatureNotSupportedException. Unlike the length variants (which throw NotImplementedException), this JDBC 4 API is marked as a feature the driver intentionally does not support.

Source

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

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

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

    @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)

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Convert the InputStream to a String and call setString(parameterIndex, value)
  2. Use the length-based APIs — note they also throw NotImplementedException in this driver, so avoid all stream setters
  3. Pass the text value via setObject
  4. Restrict to supported types: primitives, String, byte[], java.sql types

Example fix

// before
ps.setAsciiStream(1, in);
// after
ps.setString(1, new String(in.readAllBytes(), StandardCharsets.US_ASCII));
Defensive patterns

Strategy: try-catch

Validate before calling

if (value instanceof InputStream) {
    throw new IllegalStateException("Presto JDBC does not support setAsciiStream; 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.setAsciiStream(idx, is);
} catch (SQLFeatureNotSupportedException e) {
    ps.setString(idx, new String(is.readAllBytes(), StandardCharsets.US_ASCII));
}

Prevention

When it happens

Trigger: Calling PreparedStatement.setAsciiStream(parameterIndex, inputStream) (no length argument) on a PrestoPreparedStatement.

Common situations: JDBC 4.x style code omitting the length parameter; libraries that prefer the length-less stream setters when available.

Related errors


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