{"record":{"id":"799931d1dac5c21e","repo":"jd-opensource/joyagent-jdgenie","slug":"error-799931","errorCode":null,"errorMessage":"数据库联通测试失败:","messagePattern":"数据库联通测试失败:","errorType":"exception","errorClass":"JdbcBizException","httpStatus":null,"severity":"error","filePath":"genie-backend/src/main/java/com/jd/genie/data/provider/jdbc/JdbcDataProvider.java","lineNumber":98,"sourceCode":"                queryResult.setDataList(result);\n                queryResult.setDataSize((long) result.size());\n                queryResult.setQuerySql(request.getSql());\n                queryResult.setQueryEndTime(System.currentTimeMillis());\n                return queryResult;\n            }\n\n        }\n    }\n\n    @Override\n    public boolean queryForTest(JdbcQueryRequest request) {\n        boolean success = false;\n        request.getJdbcConnectionConfig().setMaxRetryTimes(1);\n        try (Connection connection = JdbcConnectionFactory.getConnection(request.getJdbcConnectionConfig()).getConnection()) {\n            success = true;\n        } catch (Exception e) {\n            log.warn(\"An error occurred while querying for test: {}\", e.getMessage(), e);\n            throw new JdbcBizException(\"数据库联通测试失败:\" + e.getMessage());\n        }\n        return success;\n    }\n\n}\n","sourceCodeStart":80,"sourceCodeEnd":104,"githubUrl":"https://github.com/jd-opensource/joyagent-jdgenie/blob/2417e0b8b636d941ad5fb14c59b20dddfef5375d/genie-backend/src/main/java/com/jd/genie/data/provider/jdbc/JdbcDataProvider.java#L80-L104","documentation":"JdbcDataProvider.queryForTest() attempts to open a physical JDBC connection using the request's connection config (with retries forced to 1) and wraps any failure in JdbcBizException '数据库联通测试失败:<cause>'. It is a connectivity smoke-test: any connection-level error (bad host, credentials, driver, timeout) surfaces here.","triggerScenarios":"Calling queryForTest(request) where JdbcConnectionFactory.getConnection(config) or connection.getConnection() throws — wrong host/port, unreachable network, bad username/password, unknown database, missing driver class, or connect timeout.","commonSituations":"User entering wrong credentials or host in a 'test connection' UI; DB firewall blocking the host; database down; JDBC URL typos; driver jar not on classpath; SSL requirement mismatch.","solutions":["Read the appended cause message and fix the underlying connection issue (host, port, username, password, database name)","Verify network reachability (telnet/nc to host:port) and firewall/security-group rules","Confirm the JDBC driver dependency for the target database is on the classpath and the URL driver class matches","Increase connectTimeout/socketTimeout appropriately and retry after confirming the DB is up"],"exampleFix":"// before\nJdbcConnectionConfig cfg = new JdbcConnectionConfig();\ncfg.setUrl(\"jdbc:mysql://localhost:3306/mydb\");\ncfg.setUsername(\"root\");\n// password missing\nprovider.queryForTest(request);\n// after\nJdbcConnectionConfig cfg = new JdbcConnectionConfig();\ncfg.setUrl(\"jdbc:mysql://localhost:3306/mydb\");\ncfg.setUsername(\"root\");\ncfg.setPassword(\"correct-password\");\ncfg.setConnectTimeoutMs(5000);\nprovider.queryForTest(request);","handlingStrategy":"try-catch","validationCode":"JdbcConnectionConfig c = request.getJdbcConnectionConfig();\nif (c == null || isBlank(c.getUrl()) || isBlank(c.getUsername()) || isBlank(c.getPassword()))\n    throw new IllegalArgumentException(\"url, username and password are required\");\ntry (Socket s = new Socket()) {\n    s.connect(new InetSocketAddress(hostFrom(c.getUrl()), portFrom(c.getUrl())), 3000);\n} catch (IOException e) {\n    throw new IllegalStateException(\"Host unreachable: \" + hostFrom(c.getUrl()), e);\n}","typeGuard":null,"tryCatchPattern":"try {\n    boolean ok = provider.queryForTest(request);\n} catch (JdbcBizException e) {\n    log.warn(\"DB connectivity test failed: {}\", e.getMessage());\n    return TestResult.fail(\"Cannot reach database: \" + rootCauseMessage(e));\n}","preventionTips":["Validate connection fields (url, username, password) before running the test","Pre-check network reachability (host:port) to distinguish firewall vs credential errors","Set explicit connectTimeout/socketTimeout so tests fail fast instead of hanging","Ensure the correct JDBC driver dependency is packaged with the app"],"tags":["jdbc","connection","connectivity-test","database"],"backgroundTag":"connection-refused","analyzedSha":"2417e0b8b636d941ad5fb14c59b20dddfef5375d","analyzedAt":"2026-09-08T11:28:19.414Z","contentChangedAt":"2026-09-08T11:28:19.414Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}