jeecgboot/JeecgBoot · error · JeecgBootException

数据库驱动类名不能为空

Error message

数据库驱动类名不能为空

What it means

Thrown by JdbcSecurityUtil.validateDriver() when the driverClassName parameter is null or empty. This is a simple null/empty guard before checking the driver against the ALLOWED_DRIVERS whitelist. Called from DynamicDBUtil and SysDataSourceController when creating or updating a dynamic data source.

Source

Thrown at jeecg-boot/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/security/JdbcSecurityUtil.java:126

        String lowerUrl = jdbcUrl.toLowerCase();

        for (String unsafeParam : UNSAFE_PARAMS) {
            if (lowerUrl.contains(unsafeParam)) {
                throw new JeecgBootException("连接地址有安全风险,包含不安全参数【" + unsafeParam + "】");
            }
        }
    }

    /**
     * 校验驱动类名是否在白名单中
     *
     * @param driverClassName JDBC 驱动类名
     * @throws JeecgBootException 驱动不在白名单时抛出
     */
    public static void validateDriver(String driverClassName) {
        if (oConvertUtils.isEmpty(driverClassName)) {
            throw new JeecgBootException("数据库驱动类名不能为空");
        }
        for (String allowed : ALLOWED_DRIVERS) {
            if (allowed.equals(driverClassName)) {
                return;
            }
        }
        throw new JeecgBootException("不支持的数据库驱动【" + driverClassName + "】,如需支持请联系管理员");
    }
}

View on GitHub (pinned to 96fb33f5ec)

Solutions

  1. Provide a valid JDBC driver class name in the dbDriver field (e.g., 'com.mysql.cj.jdbc.Driver' for MySQL 5.7+).
  2. Add front-end validation requiring the driver field before form submission.
  3. Use a database-type-to-driver mapping in the front-end to auto-fill the driver when the DB type is selected.

Example fix

// before
sysDataSource.setDbDriver(""); // or null
JdbcSecurityUtil.validateDriver(sysDataSource.getDbDriver()); // throws

// after
sysDataSource.setDbDriver("com.mysql.cj.jdbc.Driver");
JdbcSecurityUtil.validateDriver(sysDataSource.getDbDriver()); // passes
Defensive patterns

Strategy: validation

Validate before calling

if (oConvertUtils.isEmpty(driverClassName)) {
    return Result.error("请选择数据库驱动");
}
JdbcSecurityUtil.validateDriver(driverClassName);

Try / catch

try {
    JdbcSecurityUtil.validateDriver(driverClassName);
} catch (JeecgBootException e) {
    return Result.error(e.getMessage());
}

Prevention

When it happens

Trigger: Creating a dynamic data source (via SysDataSourceController add/update API or DynamicDBUtil.addDynamicDataSource) with a null or blank dbDriver field; the front-end data source form submits without selecting a driver class.

Common situations: Admin saves a data source configuration but leaves the driver class field empty; a migration script or API call omits the dbDriver property; the driver field is conditionally set based on database type but the condition was not met.

Related errors


AI-assisted analysis of jeecgboot/JeecgBoot@96fb33f5ec (2026-08-14). Data as JSON: /api/errors/d08aae44c4d89205. Report an issue: GitHub.