elunez/eladmin · error · RuntimeException
Get class name error: ={jdbcUrl}
Error message
Get class name error: ={jdbcUrl} What it means
SqlUtils.getDataSource calls DriverManager.getDriver(jdbcUrl.trim()) to auto-detect the JDBC driver class; when this throws SQLException the URL cannot be matched to any loaded driver, so the raw RuntimeException 'Get class name error: =<jdbcUrl>' is thrown. The odd '= ' in the message is a formatting artifact of the source ('error: =' + jdbcUrl). It means the JDBC URL is malformed or no driver jar for that database type is on the classpath.
Source
Thrown at eladmin-system/src/main/java/me/zhengjie/modules/maint/util/SqlUtils.java:55
*/
@Slf4j
public class SqlUtils {
/**
* 获取数据源
*
* @param jdbcUrl /
* @param userName /
* @param password /
* @return DataSource
*/
private static DataSource getDataSource(String jdbcUrl, String userName, String password) {
DruidDataSource druidDataSource = new DruidDataSource();
String className;
try {
className = DriverManager.getDriver(jdbcUrl.trim()).getClass().getName();
} catch (SQLException e) {
throw new RuntimeException("Get class name error: =" + jdbcUrl);
}
if (StringUtils.isEmpty(className)) {
DataTypeEnum dataTypeEnum = DataTypeEnum.urlOf(jdbcUrl);
if (null == dataTypeEnum) {
throw new RuntimeException("Not supported data type: jdbcUrl=" + jdbcUrl);
}
druidDataSource.setDriverClassName(dataTypeEnum.getDriver());
} else {
druidDataSource.setDriverClassName(className);
}
// 去掉不安全的参数
jdbcUrl = sanitizeJdbcUrl(jdbcUrl);
druidDataSource.setUrl(jdbcUrl);
druidDataSource.setUsername(userName);
druidDataSource.setPassword(password);
// 配置获取连接等待超时的时间View on GitHub (pinned to 55fbf70595)
Solutions
- Correct the jdbcUrl — it must start with 'jdbc:<subprotocol>:...' (e.g. 'jdbc:mysql://host:3306/db').
- Add the corresponding JDBC driver dependency to the eladmin-system module if connecting to a non-MySQL database.
- Trim/clean the URL before saving; note the code already trims for detection but stores sanitizeJdbcUrl(jdbcUrl) afterwards.
Example fix
// before String url = "mysql://127.0.0.1:3306/db"; // missing jdbc: prefix -> SQLException // after String url = "jdbc:mysql://127.0.0.1:3306/db?useSSL=false&serverTimezone=Asia/Shanghai";
Defensive patterns
Strategy: validation
Validate before calling
// validate a JDBC URL before passing it to SqlUtils
private static final Pattern JDBC_URL = Pattern.compile("^\\s*jdbc:[a-z0-9]+:.*", Pattern.CASE_INSENSITIVE);
boolean ok = jdbcUrl != null && JDBC_URL.matcher(jdbcUrl).matches();
if (!ok) throw new IllegalArgumentException("Invalid JDBC URL: " + jdbcUrl); Try / catch
try { SqlUtils.executeQuery(url, user, pwd, sql, 10); } catch (RuntimeException e) { if (e.getMessage().startsWith("Get class name error")) { showFieldError("jdbcUrl", "URL格式错误或驱动缺失"); return; } throw e; } Prevention
- Always start URLs with 'jdbc:<subprotocol>:' and test them in a standalone JDBC client first.
- Add the driver dependency for every database brand you intend to connect to from the maintenance tool.
- Paste URLs from official driver docs, not from chat/email, to avoid invisible characters.
When it happens
Trigger: Using the 在线数据库管理/SQL执行 feature with a datasource whose jdbcUrl is syntactically invalid (missing 'jdbc:', bad subprotocol like 'jdbc:oracl:...', typo) or points to a database whose driver jar (Oracle, SQL Server, etc.) is not bundled. DriverManager.getDriver only accepts URLs with a registered driver.
Common situations: Typo in the JDBC URL configured in the maintenance datasource form; using jdbc:oracle/oracle-like URLs when only MySQL's driver is on the classpath; trailing whitespace or invisible characters in a copy-pasted URL; case-sensitive subprotocol mistakes.
Related errors
- Unable to get driver instance: {jdbcUrl}
- Not supported data type: jdbcUrl={jdbcUrl}
- create connection error, jdbcUrl: {jdbcUrl}
- Database not exist
- IP对应服务器信息不存在:{ip}
AI-assisted analysis of elunez/eladmin@55fbf70595 (2026-08-14).
Data as JSON: /api/errors/7861cd9e09d9db4e.
Report an issue: GitHub.