Browse Source

BI-100757 fix:使用自定义驱动,mysql数据连接连接不上

feature/x
Roger.Chen 3 years ago
parent
commit
121adcc91c
  1. 12
      fine-druid/src/main/java/com/fr/third/alibaba/druid/util/MySqlUtils.java
  2. 10
      fine-druid/src/main/java/com/fr/third/alibaba/druid/util/Utils.java

12
fine-druid/src/main/java/com/fr/third/alibaba/druid/util/MySqlUtils.java

@ -357,7 +357,6 @@ public class MySqlUtils {
}
Class<?> clazz = conn.getClass();
if (class_ConnectionImpl == null) {
if (clazz.getName().equals("com.mysql.jdbc.ConnectionImpl")) {
class_ConnectionImpl = clazz;
} else if (clazz.getName().equals("com.mysql.jdbc.Connection")) { // mysql 5.0.x
@ -367,7 +366,6 @@ public class MySqlUtils {
} else if (clazz.getSuperclass().getName().equals("com.mysql.jdbc.ConnectionImpl")) {
class_ConnectionImpl = clazz.getSuperclass();
}
}
if (class_ConnectionImpl == clazz || class_ConnectionImpl == clazz.getSuperclass()) {
try {
@ -387,7 +385,7 @@ public class MySqlUtils {
}
public static long getLastPacketReceivedTimeMs(Connection conn) throws SQLException {
if (class_connectionImpl == null && !class_connectionImpl_Error) {
if (!class_connectionImpl_Error) {
try {
class_connectionImpl = Utils.loadClass("com.mysql.jdbc.MySQLConnection");
if (class_connectionImpl == null) {
@ -406,9 +404,7 @@ public class MySqlUtils {
}
if(mysqlJdbcVersion6){
if (classJdbc == null) {
classJdbc = Utils.loadClass("com.mysql.cj.jdbc.JdbcConnection");
}
if (classJdbc == null) {
return -1;
@ -441,7 +437,7 @@ public class MySqlUtils {
throw new SQLException("getIdleFor error", e);
}
} else {
if (method_getIO == null && !method_getIO_error) {
if (!method_getIO_error) {
try {
method_getIO = class_connectionImpl.getMethod("getIO");
} catch (Throwable error) {
@ -453,7 +449,7 @@ public class MySqlUtils {
return -1;
}
if (class_MysqlIO == null && !class_MysqlIO_Error) {
if (!class_MysqlIO_Error) {
try {
class_MysqlIO = Utils.loadClass("com.mysql.jdbc.MysqlIO");
} catch (Throwable error) {
@ -465,7 +461,7 @@ public class MySqlUtils {
return -1;
}
if (method_getLastPacketReceivedTimeMs == null && !method_getLastPacketReceivedTimeMs_error) {
if (!method_getLastPacketReceivedTimeMs_error) {
try {
Method method = class_MysqlIO.getDeclaredMethod("getLastPacketReceivedTimeMs");
method.setAccessible(true);

10
fine-druid/src/main/java/com/fr/third/alibaba/druid/util/Utils.java

@ -239,20 +239,20 @@ public class Utils {
return null;
}
ClassLoader ctxClassLoader = Thread.currentThread().getContextClassLoader();
if (ctxClassLoader != null) {
try {
return Class.forName(className);
return clazz = ctxClassLoader.loadClass(className);
} catch (ClassNotFoundException e) {
// skip
}
}
ClassLoader ctxClassLoader = Thread.currentThread().getContextClassLoader();
if (ctxClassLoader != null) {
try {
clazz = ctxClassLoader.loadClass(className);
clazz = Class.forName(className);
} catch (ClassNotFoundException e) {
// skip
}
}
return clazz;
}

Loading…
Cancel
Save