{"record":{"id":"cf7b93beb99f14e7","repo":"tursodatabase/turso","slug":"column-name-columnname-not-found","errorCode":null,"errorMessage":"column name {columnName} not found","messagePattern":"column name (.+?) not found","errorType":"exception","errorClass":"java.sql.SQLException","httpStatus":null,"severity":"error","filePath":"bindings/java/src/main/java/tech/turso/core/TursoResultSet.java","lineNumber":156,"sourceCode":"  public void checkOpen() throws SQLException {\n    if (!open) {\n      throw new SQLException(\"ResultSet closed\");\n    }\n  }\n\n  public void close() throws SQLException {\n    this.open = false;\n  }\n\n  public Object get(String columnName) throws SQLException {\n    final int columnsLength = this.columnNames.length;\n    for (int i = 0; i < columnsLength; i++) {\n      if (this.columnNames[i].equals(columnName)) {\n        return get(i + 1);\n      }\n    }\n\n    throw new SQLException(\"column name \" + columnName + \" not found\");\n  }\n\n  public Object get(int columnIndex) throws SQLException {\n    if (!this.isOpen()) {\n      throw new SQLException(\"ResultSet is not open\");\n    }\n\n    if (this.lastStepResult == null || this.lastStepResult.getResult() == null) {\n      throw new SQLException(\"ResultSet is null\");\n    }\n\n    final Object[] resultSet = this.lastStepResult.getResult();\n    if (columnIndex > resultSet.length || columnIndex < 0) {\n      throw new SQLException(\"columnIndex out of bound\");\n    }\n\n    return resultSet[columnIndex - 1];\n  }","sourceCodeStart":138,"sourceCodeEnd":174,"githubUrl":"https://github.com/tursodatabase/turso/blob/244cde92a7df7f9b8b8b7a4075c35a12977e303e/bindings/java/src/main/java/tech/turso/core/TursoResultSet.java#L138-L174","documentation":"get(String columnName) performs a linear scan of the columnNames array using exact, case-sensitive equals(); if no element matches the argument it throws. There is no case-insensitive fallback and no metadata lookup, so the argument must match the SQL-produced name byte for byte — quoted identifiers keep their case and any whitespace.","triggerScenarios":"Requesting 'Name' when the query yields 'name'; using the table's column name when the SELECT list aliases it (SELECT x AS y); asking for a column not present in the SELECT list; requesting the table-qualified 't.id' when the result name is just 'id'.","commonSituations":"SELECT * with case differences between schema and reader constants; expression columns with engine-generated names; refactors renaming columns while reader code lags; whitespace in config-driven column names.","solutions":["Inspect rs.getColumnNames() and use the exact element returned","Make both sides agree explicitly: alias in SQL (SELECT x AS name) and use that alias in code","Resolve the index yourself case-insensitively from getColumnNames(), then call get(int)","Switch to positional get(int) when column names are unstable"],"exampleFix":"// before\nObject v = rs.get(\"UserName\"); // column is 'username' -> throws\n\n// after\nString[] cols = rs.getColumnNames();\nint idx = -1;\nfor (int i = 0; i < cols.length; i++) {\n  if (cols[i].equalsIgnoreCase(\"UserName\")) { idx = i + 1; break; }\n}\nif (idx == -1) throw new IllegalArgumentException(\"no column 'UserName' in \" + java.util.Arrays.toString(cols));\nObject v = rs.get(idx);","handlingStrategy":"validation","validationCode":"String[] cols = rs.getColumnNames();\nint idx = -1;\nfor (int i = 0; i < cols.length; i++) {\n  if (cols[i].equals(wanted) || cols[i].equalsIgnoreCase(wanted)) { idx = i + 1; break; }\n}\nif (idx == -1) {\n  throw new IllegalArgumentException(\n      \"no column '\" + wanted + \"' in \" + Arrays.toString(cols));\n}\nObject v = rs.get(idx);","typeGuard":null,"tryCatchPattern":"try {\n  return rs.get(\"username\");\n} catch (SQLException e) {\n  throw new IllegalArgumentException(\n      \"unknown column; available: \" + Arrays.toString(rs.getColumnNames()), e);\n}","preventionTips":["Alias columns explicitly in SELECT (AS name) so SQL and reader agree","For SELECT * result sets, resolve indexes once via getColumnNames(), then use get(int)","Keep one constants class for column names shared by SQL text and readers"],"tags":["java","jdbc","result-set","column","case-sensitivity"],"backgroundTag":"column-not-found","analyzedSha":"244cde92a7df7f9b8b8b7a4075c35a12977e303e","analyzedAt":"2026-08-20T07:02:18.389Z","contentChangedAt":"2026-08-20T07:02:18.389Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}