{"record":{"id":"8e8bf5df87c6b3ea","repo":"tursodatabase/turso","slug":"cannot-convert-value-to-timestamp-type","errorCode":null,"errorMessage":"Cannot convert value to Timestamp: {type}","messagePattern":"Cannot convert value to Timestamp: (.+?)","errorType":"exception","errorClass":"SQLException","httpStatus":null,"severity":"error","filePath":"bindings/java/src/main/java/tech/turso/jdbc4/JDBC4ResultSet.java","lineNumber":230,"sourceCode":"\n  @Override\n  @SkipNullableCheck\n  public Timestamp getTimestamp(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            byte[] bytes = (byte[]) result;\n            if (bytes.length == Long.BYTES) {\n              long time = ByteBuffer.wrap(bytes).getLong();\n              return new Timestamp(time);\n            }\n          }\n          throw new SQLException(\"Cannot convert value to Timestamp: \" + result.getClass());\n        });\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          }","sourceCodeStart":212,"sourceCodeEnd":248,"githubUrl":"https://github.com/tursodatabase/turso/blob/bad083fafbefdeae9a42ec19bdaaad8918dcf411/bindings/java/src/main/java/tech/turso/jdbc4/JDBC4ResultSet.java#L212-L248","documentation":"getTimestamp(int) accepts only the driver's 8-byte epoch-millis blob written by setTimestamp (Long.BYTES buffer, putLong). TEXT timestamps ('2024-01-31 10:00:00') and INTEGER epoch columns arrive as String/Long and throw with the actual class name. Unlike getTime, this message correctly says 'Timestamp'.","triggerScenarios":"rs.getTimestamp() on TEXT or INTEGER timestamp columns; timestamps written by other tools/drivers as strings; DEFAULT CURRENT_TIMESTAMP columns that SQLite stores as text.","commonSituations":"Schemas shared with other SQLite writers; migrated datasets keeping text timestamps; assuming other drivers' lenient getTimestamp coercion.","solutions":["Parse in Java: Timestamp.valueOf(rs.getString(i)) for 'yyyy-mm-dd hh:mm:ss[.fff]', Timestamp.from(Instant.parse(s)) for ISO-8601, or new Timestamp(rs.getLong(i)) for epoch millis.","Write with setTimestamp() so the blob round-trips.","Or transform in SQL (strftime / CAST) so the value arrives in the shape you parse."],"exampleFix":"// before\nTimestamp ts = rs.getTimestamp(1); // TEXT column -> throws\n\n// after\nTimestamp ts = Timestamp.valueOf(rs.getString(1));","handlingStrategy":"type-guard","validationCode":"Object v = rs.getObject(1);\nTimestamp ts = (v == null) ? null\n    : isDriverDateBlob(v) ? rs.getTimestamp(1)\n    : Timestamp.valueOf(rs.getString(1)); // 'yyyy-mm-dd hh:mm:ss[.fff]' fallback","typeGuard":"static boolean isDriverDateBlob(Object v) {\n    return v instanceof byte[] b && b.length == Long.BYTES;\n}","tryCatchPattern":"try {\n    return rs.getTimestamp(i);\n} catch (SQLException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"Cannot convert value to Timestamp\")) {\n        return Timestamp.valueOf(rs.getString(i));\n    }\n    throw e;\n}","preventionTips":["Write timestamps with setTimestamp() to keep the blob round-trip intact.","Beware text defaults like CURRENT TIMESTAMP in shared schemas — parse them as strings.","Standardize one timestamp representation per column across all writers."],"tags":["jdbc","type-conversion","timestamp","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"}