Quantcast
Channel: MySQL Forums - Connector/J, JDBC and Java
Viewing all articles
Browse latest Browse all 884

ConnectionIsClosedException is not a sqlexception (no replies)

$
0
0
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。

Viewing all articles
Browse latest Browse all 884

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>