{"record":{"id":"7861cd9e09d9db4e","repo":"elunez/eladmin","slug":"get-class-name-error-jdbcurl","errorCode":null,"errorMessage":"Get class name error: ={jdbcUrl}","messagePattern":"Get class name error: =(.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":400,"severity":"error","filePath":"eladmin-system/src/main/java/me/zhengjie/modules/maint/util/SqlUtils.java","lineNumber":55,"sourceCode":" */\n@Slf4j\npublic class SqlUtils {\n\n\t/**\n\t * 获取数据源\n\t *\n\t * @param jdbcUrl /\n\t * @param userName /\n\t * @param password /\n\t * @return DataSource\n\t */\n\tprivate static DataSource getDataSource(String jdbcUrl, String userName, String password) {\n\t\tDruidDataSource druidDataSource = new DruidDataSource();\n\t\tString className;\n\t\ttry {\n\t\t\tclassName = DriverManager.getDriver(jdbcUrl.trim()).getClass().getName();\n\t\t} catch (SQLException e) {\n\t\t\tthrow new RuntimeException(\"Get class name error: =\" + jdbcUrl);\n\t\t}\n\t\tif (StringUtils.isEmpty(className)) {\n\t\t\tDataTypeEnum dataTypeEnum = DataTypeEnum.urlOf(jdbcUrl);\n\t\t\tif (null == dataTypeEnum) {\n\t\t\t\tthrow new RuntimeException(\"Not supported data type: jdbcUrl=\" + jdbcUrl);\n\t\t\t}\n\t\t\tdruidDataSource.setDriverClassName(dataTypeEnum.getDriver());\n\t\t} else {\n\t\t\tdruidDataSource.setDriverClassName(className);\n\t\t}\n\n\t\t// 去掉不安全的参数\n\t\tjdbcUrl = sanitizeJdbcUrl(jdbcUrl);\n\n\t\tdruidDataSource.setUrl(jdbcUrl);\n\t\tdruidDataSource.setUsername(userName);\n\t\tdruidDataSource.setPassword(password);\n\t\t// 配置获取连接等待超时的时间","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/elunez/eladmin/blob/55fbf705956949697dbd68bf9003776609d3d029/eladmin-system/src/main/java/me/zhengjie/modules/maint/util/SqlUtils.java#L37-L73","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nString url = \"mysql://127.0.0.1:3306/db\"; // missing jdbc: prefix -> SQLException\n// after\nString url = \"jdbc:mysql://127.0.0.1:3306/db?useSSL=false&serverTimezone=Asia/Shanghai\";","handlingStrategy":"validation","validationCode":"// validate a JDBC URL before passing it to SqlUtils\nprivate static final Pattern JDBC_URL = Pattern.compile(\"^\\\\s*jdbc:[a-z0-9]+:.*\", Pattern.CASE_INSENSITIVE);\nboolean ok = jdbcUrl != null && JDBC_URL.matcher(jdbcUrl).matches();\nif (!ok) throw new IllegalArgumentException(\"Invalid JDBC URL: \" + jdbcUrl);","typeGuard":null,"tryCatchPattern":"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; }","preventionTips":["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."],"tags":["jdbc","database","config","classpath"],"backgroundTag":null,"analyzedSha":"55fbf705956949697dbd68bf9003776609d3d029","analyzedAt":"2026-08-14T11:56:12.758Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}