{"record":{"id":"d337e9fb5050bee7","repo":"elunez/eladmin","slug":"create-connection-error-jdbcurl-jdbcurl","errorCode":null,"errorMessage":"create connection error, jdbcUrl: {jdbcUrl}","messagePattern":"create connection error, jdbcUrl: (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":400,"severity":"error","filePath":"eladmin-system/src/main/java/me/zhengjie/modules/maint/util/SqlUtils.java","lineNumber":106,"sourceCode":"\n\t\treturn druidDataSource;\n\t}\n\n\tprivate static Connection getConnection(String jdbcUrl, String userName, String password) {\n\t\tDataSource dataSource = getDataSource(jdbcUrl, userName, password);\n\t\tConnection connection = null;\n\t\ttry {\n\t\t\tconnection = dataSource.getConnection();\n\t\t} catch (Exception ignored) {}\n\t\ttry {\n\t\t\tint timeOut = 5;\n\t\t\tif (null == connection || connection.isClosed() || !connection.isValid(timeOut)) {\n\t\t\t\tlog.info(\"connection is closed or invalid, retry get connection!\");\n\t\t\t\tconnection = dataSource.getConnection();\n\t\t\t}\n\t\t} catch (Exception e) {\n\t\t\tlog.error(\"create connection error, jdbcUrl: {}\", jdbcUrl);\n\t\t\tthrow new RuntimeException(\"create connection error, jdbcUrl: \" + jdbcUrl);\n\t\t}\n\t\treturn connection;\n\t}\n\n\tprivate static void releaseConnection(Connection connection) {\n\t\tif (null != connection) {\n\t\t\ttry {\n\t\t\t\tconnection.close();\n\t\t\t} catch (Exception e) {\n\t\t\t\tlog.error(e.getMessage(),e);\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic static boolean testConnection(String jdbcUrl, String userName, String password) {\n\t\tConnection connection = null;\n\t\ttry {\n\t\t\tconnection = getConnection(jdbcUrl, userName, password);","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/elunez/eladmin/blob/55fbf705956949697dbd68bf9003776609d3d029/eladmin-system/src/main/java/me/zhengjie/modules/maint/util/SqlUtils.java#L88-L124","documentation":"SqlUtils.getConnection attempts dataSource.getConnection(); a first failure is silently swallowed, then the connection is re-checked (null/closed/isValid with a 5s timeout) and fetched again. If the second attempt also throws, the RuntimeException 'create connection error, jdbcUrl: <url>' surfaces. It means the Druid datasource could not open a JDBC connection to the target database at all.","triggerScenarios":"Using executeQuery/executeUpdate in the maintenance database tool against a datasource where the database is unreachable: wrong host/port, firewall blocking, credentials rejected, database down, or connection props (SSL/timezone) rejected by the server. The logged jdbcUrl pinpoints which datasource failed.","commonSituations":"Test/production DB not reachable from the app server; wrong username/password saved on the datasource record; MySQL 8 requiring SSL or serverTimezone parameters; Docker networking so 'localhost' in the URL points at the container itself; connection pool exhausted after the first getConnection swallowed an error.","solutions":["From the app host, verify reachability: telnet/nc <host> <port> and try a manual mysql/psql client connect with the same credentials.","Fix credentials or URL in the datasource configuration and re-test.","For MySQL 8 add 'useSSL=false&serverTimezone=Asia/Shanghai' (or a valid timezone) to the URL parameters.","Check the earlier log line 'connection is closed or invalid, retry get connection!' plus the swallowed first exception in logs to identify the true cause."],"exampleFix":"// before\njdbcUrl = \"jdbc:mysql://127.0.0.1:3306/db\";\n// after (MySQL 8 typical fix)\njdbcUrl = \"jdbc:mysql://127.0.0.1:3306/db?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true\";","handlingStrategy":"try-catch","validationCode":"// cheap pre-flight: open and close a connection before running user SQL\ntry (Connection c = DriverManager.getConnection(jdbcUrl, user, pwd)) {\n    if (!c.isValid(5)) throw new IllegalStateException(\"Connection not valid\");\n} catch (SQLException e) {\n    throw new IllegalArgumentException(\"数据库不可达: \" + e.getMessage());\n}","typeGuard":null,"tryCatchPattern":"try { return SqlUtils.executeQuery(url, u, p, sql, limit); } catch (RuntimeException e) { if (e.getMessage().contains(\"create connection error\")) { return errorResult(\"无法连接数据库，请检查地址/账号/网络: \" + url); } throw e; }","preventionTips":["Pre-flight the connection from the app host (not your laptop) with the exact URL and credentials.","Include required MySQL 8 params (useSSL, serverTimezone, allowPublicKeyRetrieval) in stored URLs.","Monitor pool health; the first getConnection failure is swallowed, so alert on the 'retry get connection' log line."],"tags":["jdbc","connection","network","database"],"backgroundTag":null,"analyzedSha":"55fbf705956949697dbd68bf9003776609d3d029","analyzedAt":"2026-08-14T11:56:12.758Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}