{"record":{"id":"170736494970ca2e","repo":"elunez/eladmin","slug":"not-supported-data-type-jdbcurl-jdbcurl","errorCode":null,"errorMessage":"Not supported data type: jdbcUrl={jdbcUrl}","messagePattern":"Not supported data type: jdbcUrl=(.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":400,"severity":"error","filePath":"eladmin-system/src/main/java/me/zhengjie/modules/maint/util/SqlUtils.java","lineNumber":60,"sourceCode":"\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// 配置获取连接等待超时的时间\n\t\tdruidDataSource.setMaxWait(3000);\n\t\t// 配置初始化大小、最小、最大\n\t\tdruidDataSource.setInitialSize(1);\n\t\tdruidDataSource.setMinIdle(1);\n\t\tdruidDataSource.setMaxActive(1);","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/elunez/eladmin/blob/55fbf705956949697dbd68bf9003776609d3d029/eladmin-system/src/main/java/me/zhengjie/modules/maint/util/SqlUtils.java#L42-L78","documentation":"Fallback branch in SqlUtils.getDataSource: if DriverManager could not determine a class name (className empty), the code tries DataTypeEnum.urlOf(jdbcUrl) to map the URL prefix to a known driver. A null return means the URL matches none of the supported DataTypeEnum prefixes (mysql, oracle, sqlserver, postgres, h2, etc.), so no driver class can be assigned and the datasource creation aborts.","triggerScenarios":"Passing a jdbcUrl whose subprotocol is not covered by DataTypeEnum — e.g. 'jdbc:db2://...', 'jdbc:mariadb://...' (if not enumerated), or a URL with a typo in the subprotocol — through the maintenance SQL tooling. Only reached when auto-detection via DriverManager also failed to yield a class name.","commonSituations":"Trying to use the online database-management module against a database brand eladmin does not enumerate (DB2, MariaDB, SQLite), or misspelling 'jdbc:mysql' as 'jdbc:mysq'. Check the DataTypeEnum source for the exact supported prefix list.","solutions":["Use a supported database URL prefix — check me.zhengjie.modules.mnt.database.DataTypeEnum for the accepted values (typically mysql, postgres, oracle, sqlserver, h2).","If you must support another database, extend DataTypeEnum with its url prefix and driver class, and add the driver dependency.","Verify the URL format matches the enum's urlOf matching logic (prefix-based, case-sensitive)."],"exampleFix":"// before\nString url = \"jdbc:mariadb://127.0.0.1:3306/db\"; // not in DataTypeEnum -> null\n// after\nString url = \"jdbc:mysql://127.0.0.1:3306/db\"; // or add MARIADB(\"jdbc:mariadb\", \"org.mariadb.jdbc.Driver\") to DataTypeEnum","handlingStrategy":"validation","validationCode":"// whitelist-check the URL prefix against the supported enum before use\nboolean supported = Arrays.stream(DataTypeEnum.values())\n    .anyMatch(e -> jdbcUrl.trim().toLowerCase().startsWith(e.getUrlPrefix().toLowerCase()));\nif (!supported) throw new IllegalArgumentException(\"Unsupported database type: \" + jdbcUrl);","typeGuard":null,"tryCatchPattern":"try { ... } catch (RuntimeException e) { if (e.getMessage().contains(\"Not supported data type\")) { notify(\"仅支持 DataTypeEnum 中列出的数据库类型\"); return; } throw e; }","preventionTips":["Read DataTypeEnum to know the exact supported prefixes before configuring a datasource.","Extend the enum (plus driver dependency) when adopting a new database rather than forcing an unsupported URL.","Centralize datasource creation so URL validation happens in one place."],"tags":["jdbc","database","config","unsupported-feature"],"backgroundTag":null,"analyzedSha":"55fbf705956949697dbd68bf9003776609d3d029","analyzedAt":"2026-08-14T11:56:12.758Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}