From b8ac15b2a107fc0dcda0fc5e75037837f900ce60 Mon Sep 17 00:00:00 2001 From: "Roger.Chen" Date: Mon, 21 Feb 2022 15:57:50 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-67030=20fix:=20mysql=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E8=BF=9E=E6=8E=A5=E6=97=A0=E6=B3=95=E6=AD=A3=E5=B8=B8=E8=BF=9E?= =?UTF-8?q?=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fr/third/alibaba/druid/util/MySqlUtils.java | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 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 5d54464f5..aa1f0c568 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,15 +386,14 @@ public class MySqlUtils { public static long getLastPacketReceivedTimeMs(Connection conn) throws SQLException { if (!class_connectionImpl_Error) { - if (conn == null) { - return -1; - } try { - //REPORT-66916 这里之前获取到的是lib下的mysql5实现,而不是自定义mysql8驱动的实现 - String className = conn.getClass().getName(); - class_connectionImpl = Utils.loadClass(className); - if (className.equals("com.mysql.cj.MysqlConnection")) { - mysqlJdbcVersion6 = true; + mysqlJdbcVersion6 = false; + class_connectionImpl = Utils.loadClass("com.mysql.jdbc.MySQLConnection"); + if (class_connectionImpl == null || class_connectionImpl.getClassLoader() != conn.getClass().getClassLoader()) { + class_connectionImpl = Utils.loadClass("com.mysql.cj.MysqlConnection"); + if (class_connectionImpl != null) { + mysqlJdbcVersion6 = true; + } } } catch (Throwable error) { class_connectionImpl_Error = true; @@ -412,7 +411,7 @@ public class MySqlUtils { return -1; } - if (getIdleFor == null && !getIdleForError) { + if (!getIdleForError) { try { getIdleFor = classJdbc.getMethod("getIdleFor"); getIdleFor.setAccessible(true);