{"record":{"id":"cb0cfe5212d79676","repo":"jd-opensource/joyagent-jdgenie","slug":"error-cb0cfe","errorCode":null,"errorMessage":"创建数据源失败","messagePattern":"创建数据源失败","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"critical","filePath":"genie-backend/src/main/java/com/jd/genie/data/jdbc/connection/JdbcConnectionPools.java","lineNumber":110,"sourceCode":"\n\n    private DatasourceWrapper refreshDatasource(JdbcConnectionConfig config) {\n        String poolId = config.getKey();\n\n        // 创建新的数据源\n        DatasourceWrapper newWrapper = createNewDatasource(config);\n        pools.put(poolId, newWrapper);\n\n        log.info(\"数据源刷新完成 poolId {}\", poolId);\n        return newWrapper;\n    }\n\n    private DatasourceWrapper createNewDatasource(JdbcConnectionConfig config) {\n        try {\n            return jdbcConnectionPoolFactory.createPooledDatasource(config);\n        } catch (Exception e) {\n            log.error(\"创建数据源失败, config: {}\", config, e);\n            throw new RuntimeException(\"创建数据源失败\", e);\n        }\n    }\n}\n","sourceCodeStart":92,"sourceCodeEnd":114,"githubUrl":"https://github.com/jd-opensource/joyagent-jdgenie/blob/2417e0b8b636d941ad5fb14c59b20dddfef5375d/genie-backend/src/main/java/com/jd/genie/data/jdbc/connection/JdbcConnectionPools.java#L92-L114","documentation":"JdbcConnectionPools.createNewDatasource wraps any exception from jdbcConnectionPoolFactory.createPooledDatasource into RuntimeException '创建数据源失败' after logging the config. It means the connection pool could not be built — typically bad JDBC config, wrong driver, or an unsupported dialect thrown by the factory.","triggerScenarios":"getOrCreateConnectionPool or newWrapper requesting a datasource whose creation fails: invalid JDBC URL, missing JDBC driver on classpath, wrong credentials, or an unsupported dialect from JdbcConnectionPoolFactory.","commonSituations":"Missing mysql-connector/clickhouse-jdbc dependency, malformed JDBC URL (bad host/port/params), password with unescaped special characters, or dialect not handled by the factory.","solutions":["Read the logged cause and the original config to find the underlying failure.","Verify the JDBC URL format and that the driver dependency is on the classpath.","Confirm the dialect is MYSQL/H2/CLICKHOUSE (else the factory throws 暂不支持).","Test credentials against the database directly.","Validate the JdbcConnectionConfig fields before pool creation."],"exampleFix":"// before\nconfig.setUrl(\"jdbc:mysql://bad-host:3306/db\"); // creation fails -> RuntimeException\n// after\nconfig.setUrl(\"jdbc:mysql://localhost:3306/mydb?useSSL=false\"); // valid URL + driver present","handlingStrategy":"try-catch","validationCode":"// Java: validate config before pool creation\nObjects.requireNonNull(config.getUrl(), \"jdbc url required\");\nObjects.requireNonNull(config.getUsername(), \"username required\");\nif (!config.getUrl().startsWith(\"jdbc:\")) {\n    throw new IllegalArgumentException(\"invalid jdbc url: \" + config.getUrl());\n}","typeGuard":null,"tryCatchPattern":"try {\n    DatasourceWrapper ds = pools.getOrCreateConnectionPool(config);\n} catch (RuntimeException e) {\n    if (\"创建数据源失败\".equals(e.getMessage())) {\n        log.error(\"pool creation failed; cause={} config={}\", e.getCause(), config, e);\n    }\n    throw e;\n}","preventionTips":["Ensure JDBC driver dependencies are on the classpath.","Validate the JDBC URL and credentials before pool creation.","Confirm dialect support before reaching pool code.","Escape special characters in passwords.","Do a startup smoke test that creates the pool once."],"tags":["jdbc","datasource","hikari","pool"],"backgroundTag":"invalid-config-value","analyzedSha":"2417e0b8b636d941ad5fb14c59b20dddfef5375d","analyzedAt":"2026-09-08T11:28:19.414Z","contentChangedAt":"2026-09-08T11:28:19.414Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}