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 d670221d24e..4f699986181 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() { Mysql config = (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); }