{"record":{"id":"0c8dc8725163e927","repo":"OtterMind/Chat2DB","slug":"failed-to-insert-excel-import-data","errorCode":null,"errorMessage":"Failed to insert excel import data: ","messagePattern":"Failed to insert excel import data: ","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":207,"sourceCode":"    }\n\n    private void insertData(List<String> sqlList) {\n        if (CollectionUtils.isEmpty(sqlList)) {\n            return;\n        }\n        createTable(currentSheet);\n        Statement statement = null;\n        ResultSet resultSet = null;\n        try {\n            statement = connection.createStatement();\n            for (String sql : sqlList) {\n                statement.addBatch(sql);\n            }\n            statement.executeBatch();\n            statement.clearBatch();\n        } catch (SQLException e) {\n            log.error(\"SQLException\", e);\n            throw new IllegalStateException(\"Failed to insert excel import data: \" + 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    private String buildInsert(String tableName, List<String> columnList, List<String> valueList) {\n        return \"INSERT INTO \" + tableName + \" (\" + String.join(\",\", columnList) + \") VALUES (\"\n                + String.join(\",\", valueList) + \")\";\n    }","sourceCodeStart":189,"sourceCodeEnd":225,"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#L189-L225","documentation":"IllegalStateException 'Failed to insert excel import data: <msg>' from ReadHeaderListener when batch-inserting parsed excel rows (statement.addBatch/executeBatch) throws a SQLException.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Read the wrapped SQLException for the offending column/SQLSTATE and correct that source cell.","Override the inferred column type at the analyze step so it accepts the data (e.g. VARCHAR larger size or TEXT).","Clean nulls/blanks in NOT NULL columns of the Excel sheet.","Verify the connection is still valid and retries the batch after fixing the row."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// validate row values fit inferred column types before batching\nfor (String sql : sqlList) { /* type-check bound values per column */ }","typeGuard":null,"tryCatchPattern":"try { statement.executeBatch(); }\ncatch (SQLException e) {\n    log.error(\"batch insert failed\", e);\n    throw new IllegalStateException(\"Failed to insert excel import data: \" + e.getMessage(), e);\n}","preventionTips":["Override inferred column types to accept the widest data in each column.","Clean NOT NULL columns and type-inconsistent cells in the source sheet.","Batch in smaller chunks to isolate the offending row."],"tags":["excel","batch-insert","h2","import"],"backgroundTag":null,"analyzedSha":"5ee1e990e73fbcae1969dc554be254fedb3ab888","analyzedAt":"2026-08-14T07:05:03.077Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}