Skip to content

Commit

Permalink
Merge pull request #1877 from ly641921791/issue_1865
Browse files Browse the repository at this point in the history
Fix #1865 use DriverManager instead of MysqlDataSource to get the connection
  • Loading branch information
KomachiSion authored Jun 10, 2020
2 parents e6c578f + e189cca commit 7f7ee0d
Showing 1 changed file with 6 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;

Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit 7f7ee0d

Please sign in to comment.