tursodatabase/turso · error · SQLException

column name not found

Error message

column name not found

What it means

findColumn() throws 'column name not found' before even scanning the columns when the label is null or empty. Every label-based getter (getString(String), getInt(String), getDate(String), ...) routes through findColumn, so a blank label surfaces from any of them.

Source

Thrown at bindings/java/src/main/java/tech/turso/jdbc4/JDBC4ResultSet.java:434

  }

  @Override
  public Object getObject(int columnIndex) throws SQLException {
    final Object result = resultSet.get(columnIndex);
    wasNull = result == null;
    return result;
  }

  @Override
  @SkipNullableCheck
  public Object getObject(String columnLabel) throws SQLException {
    return getObject(findColumn(columnLabel));
  }

  @Override
  public int findColumn(String columnLabel) throws SQLException {
    if (columnLabel == null || columnLabel.isEmpty()) {
      throw new SQLException("column name not found");
    }

    final String[] columnNames = resultSet.getColumnNames();
    for (int i = 0; i < columnNames.length; i++) {
      if (columnNames[i].equals(columnLabel)) {
        return i + 1;
      }
    }
    throw new SQLException("column name " + columnLabel + " not found");
  }

  @Override
  @SkipNullableCheck
  public Reader getCharacterStream(int columnIndex) throws SQLException {
    final Object result = resultSet.get(columnIndex);
    wasNull = result == null;
    if (result == null) {
      return null;

View on GitHub (pinned to bad083fafb)

Solutions

  1. Guard the label before use: reject null/empty with a clear IllegalArgumentException naming the caller
  2. Switch to ordinal access (rs.getX(1)) when the label cannot be trusted
  3. Log the label at the call site so blank values are visible when the failure happens

Example fix

// before
return rs.getString(columnName); // columnName == null -> "column name not found"

// after
if (columnName == null || columnName.isEmpty()) {
  throw new IllegalArgumentException("column label must be set, got: " + columnName);
}
return rs.getString(columnName);
Defensive patterns

Strategy: validation

Validate before calling

// Validate before any label-based getter (they all route through findColumn)
if (label == null || label.isEmpty()) {
  throw new IllegalArgumentException("column label required, got: " + label);
}

Type guard

static boolean usableLabel(String label) {
  return label != null && !label.isEmpty();
}

Try / catch

try {
  int idx = rs.findColumn(label);
} catch (SQLException e) {
  if (!String.valueOf(e.getMessage()).startsWith("column name")) throw e;
  throw new IllegalStateException("blank or null column label at this call site", e);
}

Prevention

When it happens

Trigger: rs.getX(null) or rs.getX("") - usually a label variable that was never set: a Map.get() miss, a config key typo, or a string built by concatenation that came out empty.

Common situations: Column names driven by configuration or user input; refactors that leave constants null; whitespace-only labels trimmed to empty; loop variables over a sparse key map.

Related errors


AI-assisted analysis of tursodatabase/turso@bad083fafb (2026-08-16). Data as JSON: /api/errors/55cc8aed336320c9. Report an issue: GitHub.