{"record":{"id":"3209c26125d99b18","repo":"mybatis/mybatis-3","slug":"error-attempting-to-get-column-columnindex","errorCode":null,"errorMessage":"Error attempting to get column #\" + columnIndex + \" from result set.  Cause: \" + e","messagePattern":"Error attempting to get column #\" \\+ columnIndex \\+ \" from result set\\.  Cause: \" \\+ e","errorType":"exception","errorClass":"ResultMapException","httpStatus":null,"severity":"error","filePath":"src/main/java/org/apache/ibatis/type/BaseTypeHandler.java","lineNumber":97,"sourceCode":"    }\n  }\n\n  @Override\n  public T getResult(ResultSet rs, String columnName) throws SQLException {\n    try {\n      return getNullableResult(rs, columnName);\n    } catch (Exception e) {\n      throw new ResultMapException(\"Error attempting to get column '\" + columnName + \"' from result set.  Cause: \" + e,\n          e);\n    }\n  }\n\n  @Override\n  public T getResult(ResultSet rs, int columnIndex) throws SQLException {\n    try {\n      return getNullableResult(rs, columnIndex);\n    } catch (Exception e) {\n      throw new ResultMapException(\"Error attempting to get column #\" + columnIndex + \" from result set.  Cause: \" + e,\n          e);\n    }\n  }\n\n  @Override\n  public T getResult(CallableStatement cs, int columnIndex) throws SQLException {\n    try {\n      return getNullableResult(cs, columnIndex);\n    } catch (Exception e) {\n      throw new ResultMapException(\n          \"Error attempting to get column #\" + columnIndex + \" from callable statement.  Cause: \" + e, e);\n    }\n  }\n\n  public abstract void setNonNullParameter(PreparedStatement ps, int i, T parameter, JdbcType jdbcType)\n      throws SQLException;\n\n  /**","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/mybatis/mybatis-3/blob/008069adb1b089579b5dcba87ee591908b263274/src/main/java/org/apache/ibatis/type/BaseTypeHandler.java#L79-L115","documentation":"Identical wrapper to the by-name variant, but the read was made by column index: getNullableResult(rs, columnIndex) threw and MyBatis reports which positional column (#1, #2, ...) failed. Index-based access is used by constructor auto-mapping and by results mapped without explicit column names.","triggerScenarios":"Constructor-based auto-mapping where the SELECT column order no longer matches the constructor argument order; an aggregate query whose column positions shifted; a handler that fails converting the value at that position.","commonSituations":"Reordering columns in a shared SELECT; adding/removing a column while relying on positional mapping; resultMap using column indexes after a query refactor.","solutions":["Use the reported index to identify which column in the SELECT failed, then check its value against the property's handler","Prefer explicit column names in the resultMap (or column aliases) instead of positional coupling","If constructor auto-mapping is used, annotate the constructor with @Param and keep the query in sync"],"exampleFix":"// before\nSELECT id, email, name ... matched to constructor (Long, String) // positional drift\n\n// after\nSELECT id, name, email ... with explicit @Param ordering in the constructor","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { ... } catch (ResultMapException e) { // message shows the 1-based index; map it back to the SELECT column order and fix ordering or handler }","preventionTips":["Prefer name-based resultMap entries over positional coupling","When using constructor auto-mapping, keep @Param-annotated constructor order aligned with the query","Review column order changes in shared SELECT fragments"],"tags":["mybatis","resultset","auto-mapping","column-index"],"backgroundTag":null,"analyzedSha":"008069adb1b089579b5dcba87ee591908b263274","analyzedAt":"2026-08-14T13:07:10.264Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}