{"record":{"id":"dd07abbffd5f3f8f","repo":"tursodatabase/turso","slug":"cannot-convert-to-unicode-stream-type","errorCode":null,"errorMessage":"Cannot convert to Unicode stream: {type}","messagePattern":"Cannot convert to Unicode stream: (.+?)","errorType":"exception","errorClass":"SQLException","httpStatus":null,"severity":"error","filePath":"bindings/java/src/main/java/tech/turso/jdbc4/JDBC4ResultSet.java","lineNumber":268,"sourceCode":"        });\n  }\n\n  @Override\n  @SkipNullableCheck\n  public InputStream getUnicodeStream(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 String) {\n            return new ByteArrayInputStream(((String) result).getBytes(\"UTF-8\"));\n          } else if (result instanceof byte[]) {\n            return new ByteArrayInputStream((byte[]) result);\n          }\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        });","sourceCodeStart":250,"sourceCodeEnd":286,"githubUrl":"https://github.com/tursodatabase/turso/blob/bad083fafbefdeae9a42ec19bdaaad8918dcf411/bindings/java/src/main/java/tech/turso/jdbc4/JDBC4ResultSet.java#L250-L286","documentation":"getUnicodeStream(int) — deprecated in JDBC since 1.2 — returns a ByteArrayInputStream for String columns (encoded UTF-8) or byte[] columns; every other runtime type throws with the class name. This driver interprets 'Unicode' as UTF-8, so streaming a TEXT column yields its UTF-8 bytes.","triggerScenarios":"rs.getUnicodeStream() on INTEGER/REAL columns or date blobs; legacy code still calling the deprecated accessor on mixed-type result sets.","commonSituations":"Old report/export code paths; schema drift via type affinity storing numbers in text-declared columns; maintainers unaware the method is deprecated.","solutions":["Replace with getString(i) and encode as needed — getUnicodeStream is deprecated anyway.","CAST numeric columns to TEXT in the query when streaming exports.","Branch on column metadata before choosing a stream getter."],"exampleFix":"// before\nInputStream is = rs.getUnicodeStream(1); // INTEGER column -> throws\n\n// after\nString s = rs.getString(1);\nInputStream is = new ByteArrayInputStream(s.getBytes(StandardCharsets.UTF_8));","handlingStrategy":"type-guard","validationCode":"Object v = rs.getObject(1);\nInputStream is = (v instanceof String s)\n    ? new ByteArrayInputStream(s.getBytes(StandardCharsets.UTF_8))\n    : rs.getUnicodeStream(1); // safe only for String/byte[] columns","typeGuard":"static boolean isUnicodeStreamable(Object v) {\n    return v instanceof String || v instanceof byte[];\n}","tryCatchPattern":"try {\n    return rs.getUnicodeStream(i);\n} catch (SQLException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"Cannot convert to Unicode stream\")) {\n        return new ByteArrayInputStream(rs.getString(i).getBytes(StandardCharsets.UTF_8));\n    }\n    throw e;\n}","preventionTips":["Replace deprecated getUnicodeStream with getString in modern code.","Verify column types before streaming in generic exporters.","Watch SQLite type affinity silently converting text columns to numeric storage."],"tags":["jdbc","type-conversion","unicode-stream","deprecated","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"}