{"record":{"id":"eec91d179a382127","repo":"testcontainers/testcontainers-java","slug":"could-not-get-driver","errorCode":null,"errorMessage":"Could not get Driver","messagePattern":"Could not get Driver","errorType":"exception","errorClass":"NoDriverFoundException","httpStatus":null,"severity":"error","filePath":"modules/jdbc/src/main/java/org/testcontainers/containers/JdbcDatabaseContainer.java","lineNumber":235,"sourceCode":"\n    @Override\n    protected void containerIsStarted(InspectContainerResponse containerInfo) {\n        logger().info(\"Container is started (JDBC URL: {})\", this.getJdbcUrl());\n        runInitScriptIfRequired();\n    }\n\n    /**\n     * Obtain an instance of the correct JDBC driver for this particular database container type\n     *\n     * @return a JDBC Driver\n     */\n    public Driver getJdbcDriverInstance() throws NoDriverFoundException {\n        synchronized (DRIVER_LOAD_MUTEX) {\n            if (driver == null) {\n                try {\n                    driver = (Driver) Class.forName(this.getDriverClassName()).newInstance();\n                } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {\n                    throw new NoDriverFoundException(\"Could not get Driver\", e);\n                }\n            }\n        }\n\n        return driver;\n    }\n\n    /**\n     * Creates a connection to the underlying containerized database instance.\n     *\n     * @param queryString query string parameters that should be appended to the JDBC connection URL.\n     *                    The '?' character must be included\n     * @return a Connection\n     * @throws SQLException if there is a repeated failure to create the connection\n     */\n    public Connection createConnection(String queryString) throws SQLException, NoDriverFoundException {\n        return createConnection(queryString, new Properties());\n    }","sourceCodeStart":217,"sourceCodeEnd":253,"githubUrl":"https://github.com/testcontainers/testcontainers-java/blob/8e549514e3f01c57d70546fbb8599d138f3903e5/modules/jdbc/src/main/java/org/testcontainers/containers/JdbcDatabaseContainer.java#L217-L253","documentation":"getJdbcDriverInstance() loads the JDBC driver class returned by getDriverClassName() reflectively; if instantiation or loading fails (Instantiation/IllegalAccess/ClassNotFound), it wraps the failure in NoDriverFoundException('Could not get Driver').","triggerScenarios":"Calling createConnection(...) when the JDBC driver named by getDriverClassName() (e.g. org.postgresql.Driver) is not on the classpath, or cannot be instantiated (abstract class, no no-arg constructor, private).","commonSituations":"Forgetting to add the JDBC driver dependency alongside the testcontainers module; driver only present in a different scope/module; shading that strips the driver class; a driver class name mismatch after switching database types.","solutions":["Add the JDBC driver artifact for your database (e.g. org.postgresql:postgresql, com.mysql:mysql-connector-j) to the test classpath","Verify the driver class name matches the dependency version","Run dependency:tree to confirm the driver resolves in the executing module"],"exampleFix":"// before\nnew JdbcDatabaseContainer(...); // no driver on classpath\n// after (Gradle)\ntestImplementation 'org.testcontainers:postgresql'\ntestImplementation 'org.postgresql:postgresql:42.7.3'","handlingStrategy":"validation","validationCode":"try { Class.forName(\"org.postgresql.Driver\"); } catch (ClassNotFoundException e) { throw new IllegalStateException(\"JDBC driver not on classpath\"); }","typeGuard":null,"tryCatchPattern":"try { conn = container.createConnection(\"?\"); } catch (NoDriverFoundException e) { /* add the JDBC driver dependency */ throw e; }","preventionTips":["Add the JDBC driver dependency alongside every testcontainers jdbc module","Keep driver and testcontainers module versions in sync in a shared BOM"],"tags":["jdbc","driver","classpath"],"backgroundTag":"missing-dependency","analyzedSha":"8e549514e3f01c57d70546fbb8599d138f3903e5","analyzedAt":"2026-09-12T14:56:41.227Z","contentChangedAt":"2026-09-12T14:56:41.227Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}