{"record":{"id":"f54ad260625b9dbf","repo":"tursodatabase/turso","slug":"cannot-convert-to-binary-stream-type","errorCode":null,"errorMessage":"Cannot convert to binary stream: {type}","messagePattern":"Cannot convert to binary stream: (.+?)","errorType":"exception","errorClass":"SQLException","httpStatus":null,"severity":"error","filePath":"bindings/java/src/main/java/tech/turso/jdbc4/JDBC4ResultSet.java","lineNumber":285,"sourceCode":"          }\n          throw new SQLException(\"Cannot convert to Unicode stream: \" + result.getClass());\n        });\n  }\n\n  @Override\n  @SkipNullableCheck\n  public InputStream getBinaryStream(int columnIndex) throws SQLException {\n    final Object result = resultSet.get(columnIndex);\n    wasNull = result == null;\n    if (result == null) {\n      return null;\n    }\n    return wrapTypeConversion(\n        () -> {\n          if (result instanceof byte[]) {\n            return new ByteArrayInputStream((byte[]) result);\n          }\n          throw new SQLException(\"Cannot convert to binary stream: \" + result.getClass());\n        });\n  }\n\n  @Override\n  @Nullable\n  public String getString(String columnLabel) throws SQLException {\n    return getString(findColumn(columnLabel));\n  }\n\n  @Override\n  public boolean getBoolean(String columnLabel) throws SQLException {\n    return getBoolean(findColumn(columnLabel));\n  }\n\n  @Override\n  public byte getByte(String columnLabel) throws SQLException {\n    return getByte(findColumn(columnLabel));\n  }","sourceCodeStart":267,"sourceCodeEnd":303,"githubUrl":"https://github.com/tursodatabase/turso/blob/bad083fafbefdeae9a42ec19bdaaad8918dcf411/bindings/java/src/main/java/tech/turso/jdbc4/JDBC4ResultSet.java#L267-L303","documentation":"getBinaryStream(int) accepts only byte[]/BLOB values; even String throws — unlike getAsciiStream/getUnicodeStream, which also accept String. Calling it on a TEXT column therefore fails with 'java.lang.String' named in the message. The driver performs no encoding conversion for binary streams.","triggerScenarios":"rs.getBinaryStream() on TEXT columns; on INTEGER/REAL columns; on values SQLite stored as text due to type affinity despite binary intent (e.g., hex/base64 payloads inserted as strings).","commonSituations":"Reading serialized payloads from TEXT-typed columns; other writers storing hex/base64 text where bytes were expected; generic exporters assuming every column is streamable.","solutions":["Use rs.getBytes(i) for BLOB columns; for text-encoded payloads decode deliberately: rs.getString(i).getBytes(charset) or a hex/Base64 decode.","Ensure binary data is inserted as BLOB (setBytes or setBinaryStream) so SQLite keeps it as byte[].","If another writer owns the column, align on one encoding (raw bytes vs base64) instead of mixing."],"exampleFix":"// before\nInputStream is = rs.getBinaryStream(1); // TEXT column -> throws\n\n// after\nInputStream is = new ByteArrayInputStream(rs.getString(1).getBytes(StandardCharsets.UTF_8));\n// or store the value as BLOB in the first place: ps.setBytes(1, data);","handlingStrategy":"type-guard","validationCode":"Object v = rs.getObject(1);\nInputStream is = (v instanceof byte[] bytes)\n    ? new ByteArrayInputStream(bytes)\n    : new ByteArrayInputStream(rs.getString(1).getBytes(StandardCharsets.UTF_8));","typeGuard":"static boolean isBinaryStreamable(Object v) {\n    return v instanceof byte[]; // String is NOT accepted by getBinaryStream\n}","tryCatchPattern":"try {\n    return rs.getBinaryStream(i);\n} catch (SQLException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"Cannot convert to binary stream\")) {\n        return new ByteArrayInputStream(rs.getBytes(i)); // or decode rs.getString explicitly\n    }\n    throw e;\n}","preventionTips":["Insert binary data with setBytes/setBinaryStream so SQLite stores it as BLOB, not TEXT.","Remember getBinaryStream rejects String — unlike getAsciiStream/getUnicodeStream.","Align on one payload encoding (raw bytes vs hex/base64) with every writer of the column."],"tags":["jdbc","type-conversion","binary-stream","blob","sqlite-typing"],"backgroundTag":"jdbc-type-conversion-failed","analyzedSha":"bad083fafbefdeae9a42ec19bdaaad8918dcf411","analyzedAt":"2026-08-16T23:12:11.798Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}