{"record":{"id":"093a8026e3c77891","repo":"elunez/eladmin","slug":"unable-to-get-driver-instance-jdbcurl","errorCode":null,"errorMessage":"Unable to get driver instance: {jdbcUrl}","messagePattern":"Unable to get driver instance: (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":400,"severity":"critical","filePath":"eladmin-system/src/main/java/me/zhengjie/modules/maint/domain/enums/DataTypeEnum.java","lineNumber":105,"sourceCode":"        this.desc = desc;\n        this.driver = driver;\n        this.keywordPrefix = keywordPrefix;\n        this.keywordSuffix = keywordSuffix;\n        this.aliasPrefix = aliasPrefix;\n        this.aliasSuffix = aliasSuffix;\n    }\n\n    public static DataTypeEnum urlOf(String jdbcUrl) {\n        String url = jdbcUrl.toLowerCase().trim();\n        for (DataTypeEnum dataTypeEnum : values()) {\n            if (url.startsWith(JDBC_URL_PREFIX + dataTypeEnum.feature)) {\n                try {\n                    Class<?> aClass = Class.forName(dataTypeEnum.getDriver());\n                    if (null == aClass) {\n                        throw new RuntimeException(\"Unable to get driver instance for jdbcUrl: \" + jdbcUrl);\n                    }\n                } catch (ClassNotFoundException e) {\n                    throw new RuntimeException(\"Unable to get driver instance: \" + jdbcUrl);\n                }\n                return dataTypeEnum;\n            }\n        }\n        return null;\n    }\n\n    public String getFeature() {\n        return feature;\n    }\n\n    public String getDesc() {\n        return desc;\n    }\n\n    public String getDriver() {\n        return driver;\n    }","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/elunez/eladmin/blob/55fbf705956949697dbd68bf9003776609d3d029/eladmin-system/src/main/java/me/zhengjie/modules/maint/domain/enums/DataTypeEnum.java#L87-L123","documentation":"DataTypeEnum.urlOf maps a JDBC url prefix (jdbc:mysql, jdbc:oracle, jdbc:postgresql, jdbc:sqlserver) to an enum and verifies the driver class is loadable. ClassNotFoundException is rethrown as RuntimeException('Unable to get driver instance: <url>') — the URL matched a known database type but its JDBC driver jar is not on the classpath.","triggerScenarios":"Registering or connecting a 'Database' in the maintenance module with, e.g., jdbc:postgresql://... when the PostgreSQL driver dependency is absent (eladmin ships only MySQL by default). Also slightly-mangled URLs still starting with a known prefix while the driver jar was excluded by shading/provided scope.","commonSituations":"Using the opsmnt/database-maintenance feature against Oracle/SQLServer/PostgreSQL without adding the corresponding driver to the pom; slimming dependencies for Docker and accidentally removing drivers; upgrading the JDK so an old driver fails to load.","solutions":["Add the matching JDBC driver dependency to eladmin-system/pom.xml (e.g. org.postgresql:postgresql, com.oracle.database.jdbc:ojdbc8, com.microsoft.sqlserver:mssql-jdbc) and rebuild.","Verify the jar actually lands in the final artifact (check BOOT-INF/lib or the lib dir) — beware provided/excluded scopes.","After adding the driver, retest with a simple JDBC connect before registering the Database record.","If the URL itself is wrong, correct it in the Database form so it matches the intended prefix."],"exampleFix":"<!-- before: only mysql present -->\n<dependency>\n  <groupId>mysql</groupId>\n  <artifactId>mysql-connector-java</artifactId>\n</dependency>\n\n<!-- after: add the driver your jdbc url needs -->\n<dependency>\n  <groupId>org.postgresql</groupId>\n  <artifactId>postgresql</artifactId>\n  <version>42.7.3</version>\n</dependency>","handlingStrategy":"validation","validationCode":"// Verify driver availability before registering the Database\nString url = dto.getJdbcUrl();\nDataTypeEnum t = DataTypeEnum.urlOf(url); // throws if driver missing\nif (t == null) throw new IllegalArgumentException(\"Unsupported jdbc url: \" + url);\n// then persist the Database record","typeGuard":"boolean isSupportedJdbcUrl(String url) {\n    if (url == null) return false;\n    String u = url.toLowerCase().trim();\n    return Arrays.stream(DataTypeEnum.values())\n        .anyMatch(e -> u.startsWith(\"jdbc:\" + e.getFeature()));\n}","tryCatchPattern":"try {\n    DataTypeEnum t = DataTypeEnum.urlOf(jdbcUrl);\n} catch (RuntimeException e) {\n    if (e.getMessage().startsWith(\"Unable to get driver instance\")) {\n        throw new DeploymentException(\"Add the JDBC driver for \" + jdbcUrl + \" to the classpath\", e);\n    }\n    throw e;\n}","preventionTips":["Ship the JDBC driver dependency for every database flavor the maintenance module will touch.","Verify the final artifact contains the driver jar (unzip -l app.jar | grep postgres).","Validate jdbc url format (jdbc:<feature>:...) at form-submission time with a clear message.","After driver changes, smoke-test one connection per supported database type."],"tags":["jdbc","classpath","dependency","eladmin","database"],"backgroundTag":null,"analyzedSha":"55fbf705956949697dbd68bf9003776609d3d029","analyzedAt":"2026-08-14T11:56:12.758Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}