{"record":{"id":"880a2884c0c22178","repo":"jeecgboot/JeecgBoot","slug":"url-880a28","errorCode":null,"errorMessage":"数据源URL配置格式不正确！","messagePattern":"数据源URL配置格式不正确！","errorType":"validation","errorClass":"JeecgBootException","httpStatus":null,"severity":"error","filePath":"jeecg-boot/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/dynamic/db/DynamicDBUtil.java","lineNumber":44,"sourceCode":" * @date 2014-09-05\n */\n@Slf4j\npublic class DynamicDBUtil {\n\n    /**\n     * 获取数据源【最底层方法，不要随便调用】\n     *\n     * @param dbSource\n     * @return\n     */\n    private static DruidDataSource getJdbcDataSource(final DynamicDataSourceModel dbSource) {\n        DruidDataSource dataSource = new DruidDataSource();\n\n        String driverClassName = dbSource.getDbDriver();\n        String url = dbSource.getDbUrl();\n        // url配置成 “123” 会触发Druid死循环，一直去重复尝试连接\n        if (oConvertUtils.isEmpty(url) || !url.toLowerCase().startsWith(\"jdbc:\")) {\n            throw new JeecgBootException(\"数据源URL配置格式不正确！\");\n        }\n        // 纵深防御: 连接建立时二次校验 URL 和驱动安全性\n        JdbcSecurityUtil.validate(url);\n        JdbcSecurityUtil.validateDriver(driverClassName);\n\n        String dbUser = dbSource.getDbUsername();\n        String dbPassword = dbSource.getDbPassword();\n        dataSource.setDriverClassName(driverClassName);\n        dataSource.setUrl(url);\n        //dataSource.setValidationQuery(\"SELECT 1 FROM DUAL\");\n        dataSource.setTestWhileIdle(true);\n        dataSource.setTestOnBorrow(false);\n        dataSource.setTestOnReturn(false);\n        dataSource.setBreakAfterAcquireFailure(true);\n        //设置超时时间60秒\n        dataSource.setLoginTimeout(60);\n        dataSource.setConnectionErrorRetryAttempts(0);\n        dataSource.setUsername(dbUser);","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/jeecgboot/JeecgBoot/blob/96fb33f5ec68516da0b0147da06b2eb0419e063a/jeecg-boot/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/dynamic/db/DynamicDBUtil.java#L26-L62","documentation":"Thrown by DynamicDBUtil.getJdbcDataSource when the configured datasource URL is empty or does not start with 'jdbc:' (case-insensitive). This is a defensive guard — without it, Druid enters a reconnect loop on malformed URLs. After this check, JdbcSecurityUtil.validate(url) and validateDriver(...) run a second defense-in-depth pass.","triggerScenarios":"Adding a dynamic datasource (sys_data_source table / datasource management UI) with a typo'd URL like '123', 'mysql://localhost:3306/db' (missing jdbc:), or an empty db_url. Also triggered when a YAML/JSON import of datasources omits the jdbc: prefix.","commonSituations":"Admin copy-pastes a URL fragment without the jdbc: scheme; the URL field was bound to the wrong form input; a migration script inserted display-name strings into db_url; JDBC URL template used a wrong placeholder that resolved to blank.","solutions":["Set db_url to a full JDBC URL, e.g. 'jdbc:mysql://127.0.0.1:3306/jeecg?useSSL=false&serverTimezone=GMT%2B8'.","Verify the dynamic datasource record in sys_data_source and re-save via the datasource management screen.","Ensure driverClassName matches the URL scheme (com.mysql.cj.jdbc.Driver for jdbc:mysql).","Test the URL in a standalone JDBC client before saving it into JeecgBoot."],"exampleFix":"-- before\nUPDATE sys_data_source SET db_url = 'localhost:3306/erp' WHERE id = 1;\n\n-- after\nUPDATE sys_data_source\nSET db_url = 'jdbc:mysql://localhost:3306/erp?serverTimezone=GMT%2B8',\n    db_driver = 'com.mysql.cj.jdbc.Driver'\nWHERE id = 1;","handlingStrategy":"validation","validationCode":"if (oConvertUtils.isEmpty(url) || !url.toLowerCase().startsWith(\"jdbc:\")) {\n    throw new IllegalArgumentException(\"db_url must start with jdbc:\");\n}","typeGuard":"public static boolean isJdbcUrl(String u){ return u != null && u.toLowerCase().startsWith(\"jdbc:\"); }","tryCatchPattern":"try { DynamicDBUtil.getJdbcDataSource(dbSource); }\ncatch (JeecgBootException e) { log.error(\"datasource config invalid for {}\", dbKey); }","preventionTips":["Validate the JDBC URL format in the datasource management form.","Provide URL templates per DB type in the UI.","Never store display strings in db_url."],"tags":["datasource","configuration","database","jeecg-boot","jdbc"],"backgroundTag":null,"analyzedSha":"96fb33f5ec68516da0b0147da06b2eb0419e063a","analyzedAt":"2026-08-14T00:04:16.786Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}