elunez/eladmin · critical · RuntimeException

Unable to get driver instance: {jdbcUrl}

Error message

Unable to get driver instance: {jdbcUrl}

What it means

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.

Source

Thrown at eladmin-system/src/main/java/me/zhengjie/modules/maint/domain/enums/DataTypeEnum.java:105

        this.desc = desc;
        this.driver = driver;
        this.keywordPrefix = keywordPrefix;
        this.keywordSuffix = keywordSuffix;
        this.aliasPrefix = aliasPrefix;
        this.aliasSuffix = aliasSuffix;
    }

    public static DataTypeEnum urlOf(String jdbcUrl) {
        String url = jdbcUrl.toLowerCase().trim();
        for (DataTypeEnum dataTypeEnum : values()) {
            if (url.startsWith(JDBC_URL_PREFIX + dataTypeEnum.feature)) {
                try {
                    Class<?> aClass = Class.forName(dataTypeEnum.getDriver());
                    if (null == aClass) {
                        throw new RuntimeException("Unable to get driver instance for jdbcUrl: " + jdbcUrl);
                    }
                } catch (ClassNotFoundException e) {
                    throw new RuntimeException("Unable to get driver instance: " + jdbcUrl);
                }
                return dataTypeEnum;
            }
        }
        return null;
    }

    public String getFeature() {
        return feature;
    }

    public String getDesc() {
        return desc;
    }

    public String getDriver() {
        return driver;
    }

View on GitHub (pinned to 55fbf70595)

Solutions

  1. 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.
  2. Verify the jar actually lands in the final artifact (check BOOT-INF/lib or the lib dir) — beware provided/excluded scopes.
  3. After adding the driver, retest with a simple JDBC connect before registering the Database record.
  4. If the URL itself is wrong, correct it in the Database form so it matches the intended prefix.

Example fix

<!-- before: only mysql present -->
<dependency>
  <groupId>mysql</groupId>
  <artifactId>mysql-connector-java</artifactId>
</dependency>

<!-- after: add the driver your jdbc url needs -->
<dependency>
  <groupId>org.postgresql</groupId>
  <artifactId>postgresql</artifactId>
  <version>42.7.3</version>
</dependency>
Defensive patterns

Strategy: validation

Validate before calling

// Verify driver availability before registering the Database
String url = dto.getJdbcUrl();
DataTypeEnum t = DataTypeEnum.urlOf(url); // throws if driver missing
if (t == null) throw new IllegalArgumentException("Unsupported jdbc url: " + url);
// then persist the Database record

Type guard

boolean isSupportedJdbcUrl(String url) {
    if (url == null) return false;
    String u = url.toLowerCase().trim();
    return Arrays.stream(DataTypeEnum.values())
        .anyMatch(e -> u.startsWith("jdbc:" + e.getFeature()));
}

Try / catch

try {
    DataTypeEnum t = DataTypeEnum.urlOf(jdbcUrl);
} catch (RuntimeException e) {
    if (e.getMessage().startsWith("Unable to get driver instance")) {
        throw new DeploymentException("Add the JDBC driver for " + jdbcUrl + " to the classpath", e);
    }
    throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of elunez/eladmin@55fbf70595 (2026-08-14). Data as JSON: /api/errors/093a8026e3c77891. Report an issue: GitHub.