OtterMind/Chat2DB · error · IllegalStateException

Failed to insert excel import data:

Error message

Failed to insert excel import data: 

What it means

IllegalStateException 'Failed to insert excel import data: <msg>' from ReadHeaderListener when batch-inserting parsed excel rows (statement.addBatch/executeBatch) throws a SQLException.

Source

Thrown at chat2db-community-server/chat2db-community-domain/chat2db-community-domain-core/src/main/java/ai/chat2db/community/domain/core/impl/excel/ReadHeaderListener.java:207

    }

    private void insertData(List<String> sqlList) {
        if (CollectionUtils.isEmpty(sqlList)) {
            return;
        }
        createTable(currentSheet);
        Statement statement = null;
        ResultSet resultSet = null;
        try {
            statement = connection.createStatement();
            for (String sql : sqlList) {
                statement.addBatch(sql);
            }
            statement.executeBatch();
            statement.clearBatch();
        } catch (SQLException e) {
            log.error("SQLException", e);
            throw new IllegalStateException("Failed to insert excel import data: " + e.getMessage(), e);
        } finally {
            try {
                if (resultSet != null) {
                    resultSet.close();
                }
                if (statement != null) {
                    statement.close();
                }
            } catch (SQLException e) {
                log.info("SQLException", e);
            }
        }
    }

    private String buildInsert(String tableName, List<String> columnList, List<String> valueList) {
        return "INSERT INTO " + tableName + " (" + String.join(",", columnList) + ") VALUES ("
                + String.join(",", valueList) + ")";
    }

View on GitHub (pinned to 5ee1e990e7)

Solutions

  1. Read the wrapped SQLException for the offending column/SQLSTATE and correct that source cell.
  2. Override the inferred column type at the analyze step so it accepts the data (e.g. VARCHAR larger size or TEXT).
  3. Clean nulls/blanks in NOT NULL columns of the Excel sheet.
  4. Verify the connection is still valid and retries the batch after fixing the row.
Defensive patterns

Strategy: try-catch

Validate before calling

// validate row values fit inferred column types before batching
for (String sql : sqlList) { /* type-check bound values per column */ }

Try / catch

try { statement.executeBatch(); }
catch (SQLException e) {
    log.error("batch insert failed", e);
    throw new IllegalStateException("Failed to insert excel import data: " + e.getMessage(), e);
}

Prevention

When it happens

Trigger: executeBatch fails on a data/type mismatch (e.g. text into a numeric inferred column), value too long for the column, null into a NOT NULL column created from buildCreateTable, or connection closed mid-batch.

Common situations: Excel cell value incompatible with the inferred column type; mixed data types within a column causing type inference to pick the wrong SQL type; large row batch where one row violates a constraint.

Related errors


AI-assisted analysis of OtterMind/Chat2DB@5ee1e990e7 (2026-08-14). Data as JSON: /api/errors/0c8dc8725163e927. Report an issue: GitHub.