elunez/eladmin · error · RuntimeException

create connection error, jdbcUrl: {jdbcUrl}

Error message

create connection error, jdbcUrl: {jdbcUrl}

What it means

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.

Source

Thrown at eladmin-system/src/main/java/me/zhengjie/modules/maint/util/SqlUtils.java:106

		return druidDataSource;
	}

	private static Connection getConnection(String jdbcUrl, String userName, String password) {
		DataSource dataSource = getDataSource(jdbcUrl, userName, password);
		Connection connection = null;
		try {
			connection = dataSource.getConnection();
		} catch (Exception ignored) {}
		try {
			int timeOut = 5;
			if (null == connection || connection.isClosed() || !connection.isValid(timeOut)) {
				log.info("connection is closed or invalid, retry get connection!");
				connection = dataSource.getConnection();
			}
		} catch (Exception e) {
			log.error("create connection error, jdbcUrl: {}", jdbcUrl);
			throw new RuntimeException("create connection error, jdbcUrl: " + jdbcUrl);
		}
		return connection;
	}

	private static void releaseConnection(Connection connection) {
		if (null != connection) {
			try {
				connection.close();
			} catch (Exception e) {
				log.error(e.getMessage(),e);
			}
		}
	}

	public static boolean testConnection(String jdbcUrl, String userName, String password) {
		Connection connection = null;
		try {
			connection = getConnection(jdbcUrl, userName, password);

View on GitHub (pinned to 55fbf70595)

Solutions

  1. From the app host, verify reachability: telnet/nc <host> <port> and try a manual mysql/psql client connect with the same credentials.
  2. Fix credentials or URL in the datasource configuration and re-test.
  3. For MySQL 8 add 'useSSL=false&serverTimezone=Asia/Shanghai' (or a valid timezone) to the URL parameters.
  4. 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.

Example fix

// before
jdbcUrl = "jdbc:mysql://127.0.0.1:3306/db";
// after (MySQL 8 typical fix)
jdbcUrl = "jdbc:mysql://127.0.0.1:3306/db?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true";
Defensive patterns

Strategy: try-catch

Validate before calling

// cheap pre-flight: open and close a connection before running user SQL
try (Connection c = DriverManager.getConnection(jdbcUrl, user, pwd)) {
    if (!c.isValid(5)) throw new IllegalStateException("Connection not valid");
} catch (SQLException e) {
    throw new IllegalArgumentException("数据库不可达: " + e.getMessage());
}

Try / catch

try { return SqlUtils.executeQuery(url, u, p, sql, limit); } catch (RuntimeException e) { if (e.getMessage().contains("create connection error")) { return errorResult("无法连接数据库,请检查地址/账号/网络: " + url); } throw e; }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of elunez/eladmin@55fbf70595 (2026-08-14). Data as JSON: /api/errors/d337e9fb5050bee7. Report an issue: GitHub.