@@ -192,17 +192,20 @@ public CallableStatement prepareCall(String sql) throws SQLException {
192192
193193 @ Override
194194 public String nativeSQL (String sql ) throws SQLException {
195+ checkNotClosed ();
195196 return NativeSql .parse (sql , client .getContext ());
196197 }
197198
198199 @ Override
199- public boolean getAutoCommit () {
200+ public boolean getAutoCommit () throws SQLException {
201+ checkNotClosed ();
200202 return (client .getContext ().getServerStatus () & ServerStatus .AUTOCOMMIT ) > 0 ;
201203 }
202204
203205 @ Override
204206 @ SuppressWarnings ("try" )
205207 public void setAutoCommit (boolean autoCommit ) throws SQLException {
208+ checkNotClosed ();
206209 if (autoCommit == getAutoCommit ()) {
207210 return ;
208211 }
@@ -216,6 +219,7 @@ public void setAutoCommit(boolean autoCommit) throws SQLException {
216219 @ Override
217220 @ SuppressWarnings ("try" )
218221 public void commit () throws SQLException {
222+ checkNotClosed ();
219223 try (ClosableLock ignore = lock .closeableLock ()) {
220224 if (forceTransactionEnd
221225 || (client .getContext ().getServerStatus () & ServerStatus .IN_TRANSACTION ) > 0 ) {
@@ -227,6 +231,7 @@ public void commit() throws SQLException {
227231 @ Override
228232 @ SuppressWarnings ("try" )
229233 public void rollback () throws SQLException {
234+ checkNotClosed ();
230235 try (ClosableLock ignore = lock .closeableLock ()) {
231236 if (forceTransactionEnd
232237 || (client .getContext ().getServerStatus () & ServerStatus .IN_TRANSACTION ) > 0 ) {
@@ -302,6 +307,7 @@ public boolean isReadOnly() {
302307 @ Override
303308 @ SuppressWarnings ("try" )
304309 public void setReadOnly (boolean readOnly ) throws SQLException {
310+ checkNotClosed ();
305311 try (ClosableLock ignore = lock .closeableLock ()) {
306312 if (this .readOnly != readOnly ) {
307313 client .setReadOnly (readOnly );
@@ -334,6 +340,7 @@ public void setSchema(String schema) throws SQLException {
334340 }
335341
336342 private String getDatabase () throws SQLException {
343+ checkNotClosed ();
337344 if (client .getContext ().hasClientCapability (Capabilities .CLIENT_SESSION_TRACK )) {
338345 return client .getContext ().getDatabase ();
339346 }
@@ -348,6 +355,7 @@ private String getDatabase() throws SQLException {
348355
349356 @ SuppressWarnings ("try" )
350357 private void setDatabase (String database ) throws SQLException {
358+ checkNotClosed ();
351359 // null catalog means keep current.
352360 // there is no possibility to set no database when one is selected
353361 if (database == null
@@ -364,6 +372,7 @@ private void setDatabase(String database) throws SQLException {
364372
365373 @ Override
366374 public int getTransactionIsolation () throws SQLException {
375+ checkNotClosed ();
367376 boolean useContextState =
368377 conf .useLocalSessionState ()
369378 || (client .getContext ().hasClientCapability (Capabilities .CLIENT_SESSION_TRACK )
@@ -409,6 +418,7 @@ public int getTransactionIsolation() throws SQLException {
409418 @ Override
410419 @ SuppressWarnings ("try" )
411420 public void setTransactionIsolation (int level ) throws SQLException {
421+ checkNotClosed ();
412422 boolean useContextState =
413423 conf .useLocalSessionState ()
414424 || (client .getContext ().hasClientCapability (Capabilities .CLIENT_SESSION_TRACK )
@@ -477,7 +487,8 @@ public SQLWarning getWarnings() throws SQLException {
477487 }
478488
479489 @ Override
480- public void clearWarnings () {
490+ public void clearWarnings () throws SQLException {
491+ checkNotClosed ();
481492 client .getContext ().setWarning (0 );
482493 }
483494
@@ -735,6 +746,7 @@ public Array createArrayOf(String typeName, Object[] elements) throws SQLExcepti
735746 }
736747
737748 public Array createArrayOf (String typeName , Object elements ) throws SQLException {
749+ checkNotClosed ();
738750 if (typeName == null ) throw exceptionFactory .notSupported ("typeName is not mandatory" );
739751 if (elements == null ) return null ;
740752
@@ -834,6 +846,7 @@ public Client getClient() {
834846 * @throws SQLException if resetting operation failed
835847 */
836848 public void reset () throws SQLException {
849+ checkNotClosed ();
837850 // COM_RESET_CONNECTION exist since mysql 5.7.3 and mariadb 10.2.4
838851 // but not possible to use it with mysql waiting for https://bugs.mysql.com/bug.php?id=97633
839852 // correction.
0 commit comments