jeecgboot/JeecgBoot · error · JeecgBootException
数据源URL配置格式不正确!
Error message
数据源URL配置格式不正确!
What it means
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.
Source
Thrown at jeecg-boot/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/dynamic/db/DynamicDBUtil.java:44
* @date 2014-09-05
*/
@Slf4j
public class DynamicDBUtil {
/**
* 获取数据源【最底层方法,不要随便调用】
*
* @param dbSource
* @return
*/
private static DruidDataSource getJdbcDataSource(final DynamicDataSourceModel dbSource) {
DruidDataSource dataSource = new DruidDataSource();
String driverClassName = dbSource.getDbDriver();
String url = dbSource.getDbUrl();
// url配置成 “123” 会触发Druid死循环,一直去重复尝试连接
if (oConvertUtils.isEmpty(url) || !url.toLowerCase().startsWith("jdbc:")) {
throw new JeecgBootException("数据源URL配置格式不正确!");
}
// 纵深防御: 连接建立时二次校验 URL 和驱动安全性
JdbcSecurityUtil.validate(url);
JdbcSecurityUtil.validateDriver(driverClassName);
String dbUser = dbSource.getDbUsername();
String dbPassword = dbSource.getDbPassword();
dataSource.setDriverClassName(driverClassName);
dataSource.setUrl(url);
//dataSource.setValidationQuery("SELECT 1 FROM DUAL");
dataSource.setTestWhileIdle(true);
dataSource.setTestOnBorrow(false);
dataSource.setTestOnReturn(false);
dataSource.setBreakAfterAcquireFailure(true);
//设置超时时间60秒
dataSource.setLoginTimeout(60);
dataSource.setConnectionErrorRetryAttempts(0);
dataSource.setUsername(dbUser);View on GitHub (pinned to 96fb33f5ec)
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.
Example fix
-- before
UPDATE sys_data_source SET db_url = 'localhost:3306/erp' WHERE id = 1;
-- after
UPDATE sys_data_source
SET db_url = 'jdbc:mysql://localhost:3306/erp?serverTimezone=GMT%2B8',
db_driver = 'com.mysql.cj.jdbc.Driver'
WHERE id = 1; Defensive patterns
Strategy: validation
Validate before calling
if (oConvertUtils.isEmpty(url) || !url.toLowerCase().startsWith("jdbc:")) {
throw new IllegalArgumentException("db_url must start with jdbc:");
} Type guard
public static boolean isJdbcUrl(String u){ return u != null && u.toLowerCase().startsWith("jdbc:"); } Try / catch
try { DynamicDBUtil.getJdbcDataSource(dbSource); }
catch (JeecgBootException e) { log.error("datasource config invalid for {}", dbKey); } Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- 动态数据源连接失败,dbKey:{dbKey}
- 表名不合法,存在SQL注入风险!--->{table}
- 字段不合法,存在SQL注入风险!--->{field}
- DaoFormat 是 minidao 保留关键字,不允许使用 ,请更改参数定义!
- 上传业务路径深度超出限制!
AI-assisted analysis of jeecgboot/JeecgBoot@96fb33f5ec (2026-08-14).
Data as JSON: /api/errors/880a2884c0c22178.
Report an issue: GitHub.