OtterMind/Chat2DB · error · IllegalStateException
Failed to create table for excel import:
Error message
Failed to create table for excel import:
What it means
IllegalStateException 'Failed to create table for excel import: <msg>' from ReadHeaderListener.createTable when the generated CREATE TABLE statement (buildCreateTable) throws a SQLException on the H2 connection.
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:129
}
sb = new StringBuilder(sb.substring(0, sb.length() - 2));
sb.append("\n );");
return sb.toString();
}
private void createTable(ExcelCheckResponse.Sheet sheet) {
String sql = buildCreateTable(sheet);
if (StringUtils.isEmpty(sql)) {
return;
}
Statement statement = null;
ResultSet resultSet = null;
try {
statement = this.connection.createStatement();
statement.execute(sql);
} catch (SQLException e) {
log.error("SQLException", e);
throw new IllegalStateException("Failed to create table for excel import: " + e.getMessage(), e);
} finally {
try {
if (resultSet != null) {
resultSet.close();
}
if (statement != null) {
statement.close();
}
} catch (SQLException e) {
log.info("SQLException", e);
}
}
}
@Override
public void invoke(Map<Integer, Object> data, AnalysisContext context) {
if (currentSheet == null) {
setCurrentSheet(context.readSheetHolder().getSheetNo());View on GitHub (pinned to 5ee1e990e7)
Solutions
- Inspect the wrapped SQLException message for the SQLSTATE (duplicate name, syntax, etc.) and fix the header/type accordingly.
- Sanitize/unique-ify column names in the Excel sheet before import.
- Drop any pre-existing import table for this sheet, or let the importer use a fresh name.
- Confirm the H2 connection used by the listener is still open.
Defensive patterns
Strategy: try-catch
Validate before calling
// preview the generated SQL and validate identifiers before execute String sql = buildCreateTable(sheet); if (sql == null || sql.isEmpty()) return;
Try / catch
try { statement.execute(sql); }
catch (SQLException e) {
log.error("create table failed: {}", sql, e);
throw new IllegalStateException("Failed to create table for excel import: " + e.getMessage(), e);
} Prevention
- Sanitize Excel header names to valid SQL identifiers.
- Avoid duplicate table names for repeated imports.
- Keep the H2 connection open for the full listener lifecycle.
When it happens
Trigger: execute(sql) fails because the generated table/column names contain illegal characters, duplicate table name, reserved keyword as column, unsupported column type mapping, or the H2 connection is closed.
Common situations: Excel header row with blank/duplicate/special-character column names; a sheet previously imported; column type inference producing an unsupported SQL type; connection dropped.
Related errors
- file not exist
- Failed to insert excel import data:
- Unsafe column type name from metadata: {typeName}
- Unsafe H2 column default from metadata: {columnDefault}
- web.not.support.db.type
AI-assisted analysis of OtterMind/Chat2DB@5ee1e990e7 (2026-08-14).
Data as JSON: /api/errors/68ceeda1521d56a2.
Report an issue: GitHub.