OtterMind/Chat2DB · critical · BusinessException

connection error

connection error

Error message

connection error

What it means

Thrown by executeDdl when Chat2DBContext.getConnection() returns null at the start of the method — a pre-flight check before delegating to execute(). Unlike the update-path 'connection error' variants, this one carries no cause or message args; it is a pure guard that the thread has a bound JDBC connection before attempting DDL. Indicates the connection context was never established for this request.

Source

Thrown at chat2db-community-server/chat2db-community-domain/chat2db-community-domain-core/src/main/java/ai/chat2db/community/domain/core/impl/db/DbDlTemplateServiceImpl.java:76

        if (StringUtils.isBlank(param.getSql())) {
            return Collections.emptyList();
        }
        long s1 = System.currentTimeMillis();
        ICommandExecutor executor = Chat2DBContext.getDbMetaData().getCommandExecutor();
        SqlExecuteRequest command = commandConverter.param2model(param);
        List<ExecuteResponse> results = executor.execute(command);
        long s2 = System.currentTimeMillis();
        log.info("execute_sql cost time:{}", s2 - s1);
        List<ExecuteResponse> r = reBuildHeader(results, param.getDataSourceId(), param.getSchemaName(),
                param.getDatabaseName());
        log.info("execute_header cost time:{}", System.currentTimeMillis() - s2);
        return r;
    }

    @Override
    public ExecuteResponse executeDdl(DbDlExecuteRequest param) {
        if (Chat2DBContext.getConnection() == null) {
            throw new BusinessException("connection error");
        }
        List<ExecuteResponse> result = execute(param);
        if (CollectionUtils.isEmpty(result)) {
            return null;
        }
        for (ExecuteResponse executeResult : result) {
            if (!Boolean.TRUE.equals(executeResult.getSuccess())) {
                return executeResult;
            }
        }
        ExecuteResponse executeResult = result.get(0);
        if (StringUtils.isBlank(param.getTableName())) {
            executeResult.setTableName(SqlUtils.extractTableName(executeResult.getOriginalSql()));
        }
        return executeResult;
    }

    @Override

View on GitHub (pinned to 5ee1e990e7)

Solutions

  1. Ensure executeDdl is called within the request lifecycle that binds a connection via connectionContextService.
  2. Verify datasource connectivity and pool health.
  3. In tests, bind a mock connection to Chat2DBContext before calling.
Defensive patterns

Strategy: validation

Validate before calling

if (Chat2DBContext.getConnection() == null) {
    // surface connection-setup error; do not call executeDdl
}

Try / catch

try {
    service.executeDdl(req);
} catch (BusinessException e) {
    if ("connection error".equals(e.getCode()) && e.getCause() == null) {
        // this is the ddl pre-flight null-connection guard
    } else { throw e; }
}

Prevention

When it happens

Trigger: Calling executeDdl(param) when no connection is bound in Chat2DBContext — e.g., the connection-scoping interceptor did not run, the pool failed to provide a connection, or a prior operation closed it.

Common situations: Service invoked outside the normal web-request connection scope; connection pool exhausted or DB unreachable so binding silently failed; unit test calling executeDdl without setting up Chat2DBContext.

Related errors


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