{"record":{"id":"68ceeda1521d56a2","repo":"OtterMind/Chat2DB","slug":"failed-to-create-table-for-excel-import","errorCode":null,"errorMessage":"Failed to create table for excel import: ","messagePattern":"Failed to create table for excel import: ","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"chat2db-community-server/chat2db-community-domain/chat2db-community-domain-core/src/main/java/ai/chat2db/community/domain/core/impl/excel/ReadHeaderListener.java","lineNumber":129,"sourceCode":"        }\n        sb = new StringBuilder(sb.substring(0, sb.length() - 2));\n        sb.append(\"\\n );\");\n        return sb.toString();\n    }\n\n    private void createTable(ExcelCheckResponse.Sheet sheet) {\n        String sql = buildCreateTable(sheet);\n        if (StringUtils.isEmpty(sql)) {\n            return;\n        }\n        Statement statement = null;\n        ResultSet resultSet = null;\n        try {\n            statement = this.connection.createStatement();\n            statement.execute(sql);\n        } catch (SQLException e) {\n            log.error(\"SQLException\", e);\n            throw new IllegalStateException(\"Failed to create table for excel import: \" + e.getMessage(), e);\n        } finally {\n            try {\n                if (resultSet != null) {\n                    resultSet.close();\n                }\n                if (statement != null) {\n                    statement.close();\n                }\n            } catch (SQLException e) {\n                log.info(\"SQLException\", e);\n            }\n        }\n    }\n\n    @Override\n    public void invoke(Map<Integer, Object> data, AnalysisContext context) {\n        if (currentSheet == null) {\n            setCurrentSheet(context.readSheetHolder().getSheetNo());","sourceCodeStart":111,"sourceCodeEnd":147,"githubUrl":"https://github.com/OtterMind/Chat2DB/blob/5ee1e990e73fbcae1969dc554be254fedb3ab888/chat2db-community-server/chat2db-community-domain/chat2db-community-domain-core/src/main/java/ai/chat2db/community/domain/core/impl/excel/ReadHeaderListener.java#L111-L147","documentation":"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.","triggerScenarios":"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.","commonSituations":"Excel header row with blank/duplicate/special-character column names; a sheet previously imported; column type inference producing an unsupported SQL type; connection dropped.","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."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// preview the generated SQL and validate identifiers before execute\nString sql = buildCreateTable(sheet);\nif (sql == null || sql.isEmpty()) return;","typeGuard":null,"tryCatchPattern":"try { statement.execute(sql); }\ncatch (SQLException e) {\n    log.error(\"create table failed: {}\", sql, e);\n    throw new IllegalStateException(\"Failed to create table for excel import: \" + e.getMessage(), e);\n}","preventionTips":["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."],"tags":["excel","ddl","h2","import"],"backgroundTag":null,"analyzedSha":"5ee1e990e73fbcae1969dc554be254fedb3ab888","analyzedAt":"2026-08-14T07:05:03.077Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}