From e189cca8f087feab56239c9fd6ac8ad32be2c966 Mon Sep 17 00:00:00 2001 From: ly <641921791@qq.com> Date: Wed, 25 Sep 2019 19:06:47 +0800 Subject: [PATCH] Fix #1865 --- .../MysqlHealthCheckProcessor.java | 22 +++++-------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/naming/src/main/java/com/alibaba/nacos/naming/healthcheck/MysqlHealthCheckProcessor.java b/naming/src/main/java/com/alibaba/nacos/naming/healthcheck/MysqlHealthCheckProcessor.java index 1ce59f46c43..de99041a16b 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/healthcheck/MysqlHealthCheckProcessor.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/healthcheck/MysqlHealthCheckProcessor.java @@ -21,17 +21,13 @@ import com.alibaba.nacos.naming.misc.Loggers; import com.alibaba.nacos.naming.misc.SwitchDomain; import com.alibaba.nacos.naming.monitor.MetricsMonitor; -import com.mysql.jdbc.jdbc2.optional.MysqlDataSource; import io.netty.channel.ConnectTimeoutException; import org.apache.commons.collections.CollectionUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.net.SocketTimeoutException; -import java.sql.Connection; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Statement; +import java.sql.*; import java.util.List; import java.util.concurrent.*; @@ -149,17 +145,11 @@ public void run() { AbstractHealthChecker.Mysql config = (AbstractHealthChecker.Mysql) cluster.getHealthChecker(); if (connection == null || connection.isClosed()) { - MysqlDataSource dataSource = new MysqlDataSource(); - dataSource.setConnectTimeout(CONNECT_TIMEOUT_MS); - dataSource.setSocketTimeout(CONNECT_TIMEOUT_MS); - dataSource.setUser(config.getUser()); - dataSource.setPassword(config.getPwd()); - dataSource.setLoginTimeout(1); - - dataSource.setServerName(ip.getIp()); - dataSource.setPort(ip.getPort()); - - connection = dataSource.getConnection(); + String url = "jdbc:mysql://" + ip.getIp() + ":" + ip.getPort() + + "?connectTimeout=" + CONNECT_TIMEOUT_MS + + "&socketTimeout=" + CONNECT_TIMEOUT_MS + + "&loginTimeout=" + 1; + connection = DriverManager.getConnection(url, config.getUser(), config.getPwd()); CONNECTION_POOL.put(key, connection); }