From 2a6aac26f6b09e848481e3e88772bc2400fd278f Mon Sep 17 00:00:00 2001 From: "Roger.Chen" Date: Thu, 17 Feb 2022 17:17:52 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-66916=20fix:=E4=BD=BF=E7=94=A8=E8=87=AA?= =?UTF-8?q?=E5=AE=9A=E4=B9=89mysql8=E9=A9=B1=E5=8A=A8=EF=BC=8C=E8=BF=9E?= =?UTF-8?q?=E6=8E=A5=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fr/third/alibaba/druid/util/MySqlUtils.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 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 ba1104129..5d54464f5 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 @@ -386,13 +386,15 @@ public class MySqlUtils { public static long getLastPacketReceivedTimeMs(Connection conn) throws SQLException { if (!class_connectionImpl_Error) { + if (conn == null) { + return -1; + } try { - class_connectionImpl = Utils.loadClass("com.mysql.jdbc.MySQLConnection"); - if (class_connectionImpl == null) { - class_connectionImpl = Utils.loadClass("com.mysql.cj.MysqlConnection"); - if (class_connectionImpl != null) { - mysqlJdbcVersion6 = true; - } + //REPORT-66916 这里之前获取到的是lib下的mysql5实现,而不是自定义mysql8驱动的实现 + String className = conn.getClass().getName(); + class_connectionImpl = Utils.loadClass(className); + if (className.equals("com.mysql.cj.MysqlConnection")) { + mysqlJdbcVersion6 = true; } } catch (Throwable error) { class_connectionImpl_Error = true; @@ -431,7 +433,7 @@ public class MySqlUtils { return System.currentTimeMillis() - ((Long) - getIdleFor.invoke(connImpl)) + getIdleFor.invoke(connImpl)) .longValue(); } catch (Exception e) { throw new SQLException("getIdleFor error", e);