{"record":{"id":"145c9a8081d68b57","repo":"t8y2/dbx","slug":"h2-jdbc-driver-rejected-url-buildjdbcurl-para","errorCode":null,"errorMessage":"H2 JDBC driver rejected URL: \" + buildJdbcUrl(params)","messagePattern":"H2 JDBC driver rejected URL: \" \\+ buildJdbcUrl\\(params\\)","errorType":"exception","errorClass":"SQLException","httpStatus":null,"severity":"error","filePath":"agents/drivers/h2/src/main/java/com/dbx/agent/h2/H2Agent.java","lineNumber":87,"sourceCode":"        if (previous != null) {\n            try {\n                previous.classLoader().close();\n            } catch (Exception error) {\n                replacement.classLoader().close();\n                throw error;\n            }\n        }\n        loadedDriver = replacement;\n    }\n\n    @Override\n    protected Connection openConnection(ConnectParams params) throws Exception {\n        if (loadedDriver == null) {\n            throw new IllegalStateException(\"H2 JDBC driver was not loaded\");\n        }\n        Connection opened = loadedDriver.driver().connect(buildJdbcUrl(params), buildConnectionProperties(params));\n        if (opened == null) {\n            throw new SQLException(\"H2 JDBC driver rejected URL: \" + buildJdbcUrl(params));\n        }\n        return opened;\n    }\n\n    @Override\n    protected void afterConnect(ConnectParams params, Connection connection) {\n        databaseName = params.getDatabase();\n        databaseMajorVersion = unchecked(() -> connection.getMetaData().getDatabaseMajorVersion());\n    }\n\n    H2DriverVersion driverVersion() {\n        return driverVersion;\n    }\n\n    boolean isVersion2OrLater() {\n        return databaseMajorVersion >= 2;\n    }\n","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/h2/src/main/java/com/dbx/agent/h2/H2Agent.java#L69-L105","documentation":"H2's java.sql.Driver.connect returns null when it does not recognize the JDBC URL. H2Agent detects this and throws SQLException('H2 JDBC driver rejected URL: ...') including the constructed URL, signaling the URL is malformed or uses an unknown scheme/protocol.","triggerScenarios":"buildJdbcUrl(params) produces a URL the H2 driver does not accept, e.g. wrong prefix, unsupported mode, or garbage from misconfigured connection properties.","commonSituations":"Typo like 'h2:mem:db' (missing jdbc:); using h2:tcp against a server that is not running with unsupported settings; property placeholder left unresolved in the URL template.","solutions":["Check the generated JDBC URL starts with jdbc:h2: and uses a valid form (jdbc:h2:mem:, file:, tcp:, etc.)","Print/log buildJdbcUrl(params) output and compare against H2 URL syntax docs","Fix ConnectParams (host, path, mode, in-memory vs server) feeding the URL builder"],"exampleFix":"// before\nString url = \"h2:mem:testdb;DB_CLOSE_DELAY=-1\"; // rejected: missing jdbc: prefix\nDriver d = DriverManager.getDriver(url); // returns null\n// after\nString url = \"jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1\";\nDriver d = DriverManager.getDriver(url); // recognized","handlingStrategy":"validation","validationCode":"String url = buildJdbcUrl(params); if (!url.startsWith(\"jdbc:h2:\")) { throw new IllegalArgumentException(\"Not a valid H2 JDBC URL: \" + url); }","typeGuard":"static boolean isH2Url(String url) { return url != null && url.startsWith(\"jdbc:h2:(mem|file|tcp|ssl|nio|mvstore)\"); }","tryCatchPattern":"try { conn = agent.connect(params); } catch (SQLException e) { if (e.getMessage() != null && e.getMessage().contains(\"rejected URL\")) { log.error(\"Malformed H2 URL: {}\", e.getMessage()); } throw e; }","preventionTips":["Always start H2 URLs with jdbc:h2: (a missing prefix is the #1 cause)","Validate URL templates so placeholders cannot reach the driver unresolved","Match URL mode (mem/file/tcp) to your deployment; run an H2 TCP server for jdbc:h2:tcp","Log the exact generated URL when connection setup fails"],"tags":["h2","jdbc","jdbc-url","connection","configuration"],"backgroundTag":"invalid-jdbc-url","analyzedSha":"c0390bff16418b651f4728520d99adf8ce48829a","analyzedAt":"2026-09-05T23:05:10.900Z","contentChangedAt":"2026-09-05T23:05:10.900Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}