ConnectionIsClosedException is not a sqlexception
Posted by: jason tian
Date: March 03, 2020 09:12PM

the exceptions that occur when someone operate the database should be a SQLException in theory,but the jdbc driver of 8.0.19 defined some exceptions in “com.mysql.cj.exceptions” all inherit CJException,not SQLException。
when i operate a closeed connection,i got a “ConnectionIsClosedException”, but test case was catch “java.sql.SQLException”,so test case got an error.
example:ConnectionTest.java's testping(),and so on.
Would any Master advise me why the exceptions in package “com.mysql.cj.exceptions” are all inherit CJException not java.sql.SQLException?

THe test case code in testsuite:
public void testPing() throws SQLException {
Connection conn2 = getConnectionWithProps((String) null);

((com.mysql.cj.jdbc.JdbcConnection) conn2).ping();
conn2.close();

try {
((com.mysql.cj.jdbc.JdbcConnection) conn2).ping();
fail("Should have failed with an exception");
} catch (SQLException sqlEx) {
// ignore for now
}

//
// This feature caused BUG#8975, so check for that too!

Properties props = new Properties();
props.setProperty(PropertyKey.autoReconnect.getKeyName(), "true");

getConnectionWithProps(props);
}



ping define code:
com.mysql.cj.jdbc.JdbcConnection.ping()
/**
* Detect if the connection is still good by sending a ping command
* to the server.
*
* @throws SQLException
* if the ping fails
*/
void ping() throws SQLException;

ConnectionIsClosedException define code:

public class ConnectionIsClosedException extends CJException {
......
}

/**
* The base unchecked exception thrown internally in connector.
*/
public class CJException extends RuntimeException {
....
}

jdk code:
public class RuntimeException extends Exception {
......
}

com.mysql.cj.exceptions.ConnectionIsClosedException is inherit CJException is not a SQLException。

Options: ReplyQuote


Subject
Written By
Posted
ConnectionIsClosedException is not a sqlexception
March 03, 2020 09:12PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.