From 763c02b86afb4bc745995251bd81e5fe4f261e93 Mon Sep 17 00:00:00 2001 From: weitingyuk Date: Mon, 7 Jun 2021 22:22:56 +0800 Subject: [PATCH] reset autcommit after unknown issue occurs --- .../user-impl/java/com/mysql/cj/jdbc/ConnectionImpl.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/user-impl/java/com/mysql/cj/jdbc/ConnectionImpl.java b/src/main/user-impl/java/com/mysql/cj/jdbc/ConnectionImpl.java index b8aa34781..19f5b24e1 100644 --- a/src/main/user-impl/java/com/mysql/cj/jdbc/ConnectionImpl.java +++ b/src/main/user-impl/java/com/mysql/cj/jdbc/ConnectionImpl.java @@ -2032,7 +2032,7 @@ void forEach(ConnectionLifecycleInterceptor each) throws SQLException { if (this.autoReconnectForPools.getValue()) { this.autoReconnect.setValue(true); } - + boolean autoCommitOld = this.session.getServerSession().isAutoCommit(); try { boolean needsSetOnServer = true; @@ -2051,6 +2051,13 @@ void forEach(ConnectionLifecycleInterceptor each) throws SQLException { this.session.execSQL(null, autoCommitFlag ? "SET autocommit=1" : "SET autocommit=0", -1, null, false, this.nullStatementResultSetFactory, null, false); } + } catch (CJException sqlE) { + // If an unknown exception other than a network exception occurs when executing setAutoCommit SQL, + // the auto commit value of server session should be reset to the previous value + if (!(sqlE instanceof CJCommunicationsException) && ER_UNKNOWN_ERROR == sqlE.getVendorCode()){ + this.session.getServerSession().setAutoCommit(autoCommitOld); + } + throw sqlE; } finally { if (this.autoReconnectForPools.getValue()) { this.autoReconnect.setValue(false);