{"record":{"id":"5c5e81bb33910089","repo":"tursodatabase/turso","slug":"column-name-columnname-not-found","errorCode":null,"errorMessage":"column name \" + columnName + \" not found","messagePattern":"column name \" \\+ columnName \\+ \" not found","errorType":"exception","errorClass":"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/bad083fafbefdeae9a42ec19bdaaad8918dcf411/bindings/java/src/main/java/tech/turso/core/TursoResultSet.java#L138-L174","documentation":"get(String columnName) does a case-sensitive linear scan over the column names returned by the native columns() call and throws when no entry equals the given name exactly. Names are whatever the engine reports for the select list — including aliases and, for bare expressions, the expression text.","triggerScenarios":"get(\"userId\") when the label is \"userid\" or \"USERID\"; querying SELECT u.name AS user_name but asking for \"name\"; unaliased expressions (SELECT COUNT(*) reports a synthesized label); accessing a column dropped in a schema change; names with stray whitespace from config files.","commonSituations":"Joins with aliases where the code uses the original column name; ORMs mapping Java field names (camelCase) onto unaliased SQL columns; schema migrations renaming columns without updating readers; duplicate column names where only the first index matches.","solutions":["Print or inspect rs.getColumnNames() and use the exact reported label","Add explicit AS aliases in the SELECT list and access by those aliases","Fall back to 1-based ordinal access get(i)","For tolerant lookup, resolve the index yourself from getColumnNames() (e.g. case-insensitively) and call get(int)"],"exampleFix":"// before\nObject v = rs.get(\"userId\"); // actual label is \"userid\" -> throws\n\n// after\n// SELECT id AS userId FROM t\nObject v = rs.get(\"userId\"); // alias matches exactly\n// or resolve defensively:\nString[] cols = rs.getColumnNames();\nfor (int i = 0; i < cols.length; i++) {\n  if (cols[i].equalsIgnoreCase(\"userId\")) { v = rs.get(i + 1); break; }\n}","handlingStrategy":"validation","validationCode":"String[] cols = rs.getColumnNames();\nint idx = -1;\nfor (int i = 0; i < cols.length; i++) {\n  if (cols[i].equalsIgnoreCase(columnName)) { idx = i; break; }\n}\nif (idx < 0) {\n  throw new IllegalArgumentException(\n      \"no column \" + columnName + \" in \" + java.util.Arrays.toString(cols));\n}\nObject v = rs.get(idx + 1);","typeGuard":"static boolean hasColumn(TursoResultSet rs, String columnName) {\n  for (String c : rs.getColumnNames()) {\n    if (c.equals(columnName)) return true;\n  }\n  return false;\n}","tryCatchPattern":null,"preventionTips":["Alias every output column in the SELECT list and access by those exact aliases","Log rs.getColumnNames() once when a query is first wired up","Remember the lookup is case-sensitive — match the SQL label character for character"],"tags":["java","jdbc","resultset","columns","schema","bindings"],"backgroundTag":"column-name-not-found","analyzedSha":"bad083fafbefdeae9a42ec19bdaaad8918dcf411","analyzedAt":"2026-08-16T23:12:11.798Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}