{"record":{"id":"b5fb1d6da03a6831","repo":"tursodatabase/turso","slug":"cannot-convert-to-ascii-stream-type","errorCode":null,"errorMessage":"Cannot convert to ASCII stream: {type}","messagePattern":"Cannot convert to ASCII stream: (.+?)","errorType":"exception","errorClass":"SQLException","httpStatus":null,"severity":"error","filePath":"bindings/java/src/main/java/tech/turso/jdbc4/JDBC4ResultSet.java","lineNumber":249,"sourceCode":"        });\n  }\n\n  @Override\n  @SkipNullableCheck\n  public InputStream getAsciiStream(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(\"US-ASCII\"));\n          } else if (result instanceof byte[]) {\n            return new ByteArrayInputStream((byte[]) result);\n          }\n          throw new SQLException(\"Cannot convert to ASCII stream: \" + result.getClass());\n        });\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          }","sourceCodeStart":231,"sourceCodeEnd":267,"githubUrl":"https://github.com/tursodatabase/turso/blob/bad083fafbefdeae9a42ec19bdaaad8918dcf411/bindings/java/src/main/java/tech/turso/jdbc4/JDBC4ResultSet.java#L231-L267","documentation":"getAsciiStream(int) returns a ByteArrayInputStream for exactly two runtime shapes: String columns (encoded US-ASCII) and byte[]/BLOB columns. Any other type (Long, Double, the 8-byte date blob, ...) throws with the class name — the driver performs no toString() coercion for streams.","triggerScenarios":"rs.getAsciiStream() on INTEGER/REAL columns; on expressions like COUNT(*); on the driver's 8-byte date/time blobs; generic exporters that stream every column of every row.","commonSituations":"Row-to-CSV export utilities; numeric aggregates expected to stream as text; schema drift turning a formerly TEXT column numeric via SQLite type affinity.","solutions":["Fall back to text yourself: new ByteArrayInputStream(rs.getString(i).getBytes(StandardCharsets.US_ASCII)) for non-text columns.","CAST in SQL: SELECT CAST(col AS TEXT) ... so the value arrives as a String.","Branch on ResultSetMetaData.getColumnType() and only call stream getters for CHAR/VARCHAR/TEXT/BINARY columns."],"exampleFix":"// before\nInputStream is = rs.getAsciiStream(1); // INTEGER column -> throws\n\n// after\nInputStream is = new ByteArrayInputStream(\n    rs.getString(1).getBytes(StandardCharsets.US_ASCII));","handlingStrategy":"type-guard","validationCode":"Object v = rs.getObject(1);\nInputStream is = (v instanceof String s)\n    ? new ByteArrayInputStream(s.getBytes(StandardCharsets.US_ASCII))\n    : rs.getAsciiStream(1); // safe only for String/byte[] columns","typeGuard":"static boolean isAsciiStreamable(Object v) {\n    return v instanceof String || v instanceof byte[];\n}","tryCatchPattern":"try {\n    return rs.getAsciiStream(i);\n} catch (SQLException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"Cannot convert to ASCII stream\")) {\n        return new ByteArrayInputStream(\n            rs.getString(i).getBytes(StandardCharsets.US_ASCII));\n    }\n    throw e;\n}","preventionTips":["In exporters, branch on column type and only stream TEXT/BLOB columns.","CAST numeric or computed columns to TEXT in the query when they must be streamed.","Prefer getString + explicit encoding over stream getters in new code."],"tags":["jdbc","type-conversion","ascii-stream","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"}