From 121adcc91c3e45be7658baa0cbc7d07a4bfa311b Mon Sep 17 00:00:00 2001 From: "Roger.Chen" Date: Tue, 8 Feb 2022 13:54:37 +0800 Subject: [PATCH] =?UTF-8?q?BI-100757=20fix:=E4=BD=BF=E7=94=A8=E8=87=AA?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=E9=A9=B1=E5=8A=A8=EF=BC=8Cmysql=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E8=BF=9E=E6=8E=A5=E8=BF=9E=E6=8E=A5=E4=B8=8D=E4=B8=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../third/alibaba/druid/util/MySqlUtils.java | 32 ++++++++----------- .../fr/third/alibaba/druid/util/Utils.java | 14 ++++---- 2 files changed, 21 insertions(+), 25 deletions(-) diff --git a/fine-druid/src/main/java/com/fr/third/alibaba/druid/util/MySqlUtils.java b/fine-druid/src/main/java/com/fr/third/alibaba/druid/util/MySqlUtils.java index b20f82192..ba1104129 100644 --- a/fine-druid/src/main/java/com/fr/third/alibaba/druid/util/MySqlUtils.java +++ b/fine-druid/src/main/java/com/fr/third/alibaba/druid/util/MySqlUtils.java @@ -357,16 +357,14 @@ 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 - class_ConnectionImpl = clazz; - } else if (clazz.getName().equals("com.mysql.cj.jdbc.ConnectionImpl")) { // mysql 5.0.x - class_ConnectionImpl = clazz; - } else if (clazz.getSuperclass().getName().equals("com.mysql.jdbc.ConnectionImpl")) { - class_ConnectionImpl = clazz.getSuperclass(); - } + if (clazz.getName().equals("com.mysql.jdbc.ConnectionImpl")) { + class_ConnectionImpl = clazz; + } else if (clazz.getName().equals("com.mysql.jdbc.Connection")) { // mysql 5.0.x + class_ConnectionImpl = clazz; + } else if (clazz.getName().equals("com.mysql.cj.jdbc.ConnectionImpl")) { // mysql 5.0.x + class_ConnectionImpl = clazz; + } else if (clazz.getSuperclass().getName().equals("com.mysql.jdbc.ConnectionImpl")) { + class_ConnectionImpl = clazz.getSuperclass(); } if (class_ConnectionImpl == clazz || class_ConnectionImpl == clazz.getSuperclass()) { @@ -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"); - } + 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); @@ -1988,4 +1984,4 @@ public class MySqlUtils { byte[] bytes = HexBin.decode(hex); return new String(bytes, BIG5); } -} +} \ No newline at end of file diff --git a/fine-druid/src/main/java/com/fr/third/alibaba/druid/util/Utils.java b/fine-druid/src/main/java/com/fr/third/alibaba/druid/util/Utils.java index 24457a9bf..c8ca0b0f5 100644 --- a/fine-druid/src/main/java/com/fr/third/alibaba/druid/util/Utils.java +++ b/fine-druid/src/main/java/com/fr/third/alibaba/druid/util/Utils.java @@ -239,21 +239,21 @@ public class Utils { return null; } - try { - return Class.forName(className); - } catch (ClassNotFoundException e) { - // skip - } - ClassLoader ctxClassLoader = Thread.currentThread().getContextClassLoader(); if (ctxClassLoader != null) { try { - clazz = ctxClassLoader.loadClass(className); + return clazz = ctxClassLoader.loadClass(className); } catch (ClassNotFoundException e) { // skip } } + try { + clazz = Class.forName(className); + } catch (ClassNotFoundException e) { + // skip + } + return clazz; }