{"record":{"id":"247dea24e294324d","repo":"alibaba/druid","slug":"create-driver-instance-error-driver-classname-c","errorCode":null,"errorMessage":"create driver instance error, driver className '{className}'","messagePattern":"create driver instance error, driver className '(.+?)'","errorType":"exception","errorClass":"SQLException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/com/alibaba/druid/proxy/DruidDriver.java","lineNumber":263,"sourceCode":"            String rawDriverClassname = JdbcUtils.getDriverClassName(restUrl);\n            config.setRawDriverClassName(rawDriverClassname);\n        }\n        config.setUrl(url);\n        return config;\n    }\n\n    public static Driver createDriver(final String className) throws SQLException {\n        Class<?> rawDriverClass = Utils.loadClass(className);\n\n        if (rawDriverClass == null) {\n            throw new SQLException(\"jdbc-driver's class not found. '\" + className + \"'\");\n        }\n\n        Driver rawDriver;\n        try {\n            rawDriver = (Driver) rawDriverClass.newInstance();\n        } catch (InstantiationException e) {\n            throw new SQLException(\"create driver instance error, driver className '\" + className + \"'\", e);\n        } catch (IllegalAccessException e) {\n            throw new SQLException(\"create driver instance error, driver className '\" + className + \"'\", e);\n        }\n\n        return rawDriver;\n    }\n\n    @Override\n    public int getMajorVersion() {\n        return this.majorVersion;\n    }\n\n    @Override\n    public int getMinorVersion() {\n        return this.minorVersion;\n    }\n\n    @Override","sourceCodeStart":245,"sourceCodeEnd":281,"githubUrl":"https://github.com/alibaba/druid/blob/fa8dc9912637a2f729eef9f55356621fec18d40e/core/src/main/java/com/alibaba/druid/proxy/DruidDriver.java#L245-L281","documentation":"DruidDriver.createDriver(className) catches InstantiationException when calling rawDriverClass.newInstance() — the driver class was loaded but could not be instantiated. InstantiationException specifically means the class is abstract, an interface, an array, a primitive, or void, or has no accessible no-arg constructor. The original InstantiationException is chained as the cause, so its message clarifies which condition applies.","triggerScenarios":"rawDriverClassName resolves to a class that is abstract or lacks a public no-arg constructor — e.g. pointing at a base class, an interface, an inner/protected class, or a driver implementation that requires constructor arguments rather than the JDBC-standard public no-arg constructor.","commonSituations":"Naming a factory or abstract base class instead of the concrete driver; pointing at an older driver that uses a singleton getInstance() pattern with a private constructor; copy-paste of a wrong/placeholder class name.","solutions":["Set rawDriverClassName to the concrete, public, no-arg-constructible driver class (the one registered in the driver's META-INF/services).","Inspect the chained InstantiationException cause for the exact reason (abstract / no constructor) and correct accordingly.","If the driver genuinely needs arguments, it is not JDBC-DriverManager-compatible — use a DataSource-based configuration instead of the proxy driver path."],"exampleFix":"// before\n// rawDriverClassName = com.mysql.cj.jdbc.MysqlDataSource // not a java.sql.Driver, no no-arg ctor pattern\n\n// after\n// rawDriverClassName = com.mysql.cj.jdbc.Driver // implements Driver, public no-arg ctor","handlingStrategy":"validation","validationCode":"Class<?> c = Utils.loadClass(className);\nif (c != null && (Modifier.isAbstract(c.getModifiers()) || Modifier.isInterface(c.getModifiers()))) {\n    throw new IllegalStateException(className + \" is abstract/interface; use the concrete Driver class\");\n}\ntry { c.getDeclaredConstructor(); } catch (NoSuchMethodException e) {\n    throw new IllegalStateException(className + \" has no no-arg constructor; not DriverManager-compatible\");\n}","typeGuard":"public static boolean instantiableDriver(String className) {\n    Class<?> c = Utils.loadClass(className);\n    if (c == null) return false;\n    int m = c.getModifiers();\n    if (Modifier.isAbstract(m) || Modifier.isInterface(m)) return false;\n    try { c.getDeclaredConstructor(); return true; } catch (NoSuchMethodException e) { return false; }\n}","tryCatchPattern":"try {\n    Driver d = DruidDriver.createDriver(className);\n} catch (SQLException e) {\n    if (e.getCause() instanceof InstantiationException) {\n        // pointed at an abstract/interface class; switch to the concrete driver\n        throw new IllegalStateException(\"use the concrete driver class, not \" + className, e);\n    }\n    throw e;\n}","preventionTips":["Point rawDriverClassName at the concrete public Driver class listed in the vendor's META-INF/services.","Validate the class is instantiable with a no-arg constructor at boot.","If the driver needs constructor args, use a DataSource-based configuration instead."],"tags":["driver-loading","instantiation","configuration","jdbc"],"backgroundTag":null,"analyzedSha":"fa8dc9912637a2f729eef9f55356621fec18d40e","analyzedAt":"2026-08-14T04:55:06.789Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}