我正在尝试制作JDBC
连接池组件,但遇到了问题。即:如何检测java.sql.SQLException
. 据说国家应该遵循SQL2003
惯例和文件中的XOPEN SQL
惯例JDK
。但是我找不到关于这两个公约的任何文件。有人可以为我提供吗?
我想知道每个状态代表什么,所以我可以决定何时完全关闭连接或重新连接。
我参考了BoneCP
. 这是发生 SQLException 时将激活的部分:
ImmutableSet<String> sqlStateDBFailureCodes = ImmutableSet.of("08001", "08007", "08S01", "57P01", "HY000");
String state = e.getSQLState();
ConnectionState connectionState = this.getConnectionHook() != null ? this.getConnectionHook().onMarkPossiblyBroken(this, state, e) : ConnectionState.NOP;
if (state == null){ // safety;
state = "08999";
}
if (((sqlStateDBFailureCodes.contains(state) || connectionState.equals(ConnectionState.TERMINATE_ALL_CONNECTIONS)) && this.pool != null) && this.pool.getDbIsDown().compareAndSet(false, true) ){
logger.error("Database access problem. Killing off all remaining connections in the connection pool. SQL State = " + state);
this.pool.connectionStrategy.terminateAllConnections();
this.pool.poisonAndRepopulatePartitions();
}
char firstChar = state.charAt(0);
if (connectionState.equals(ConnectionState.CONNECTION_POSSIBLY_BROKEN) || state.equals("40001") ||
state.startsWith("08") || (firstChar >= '5' && firstChar <='9') /*|| (firstChar >='I' && firstChar <= 'Z')*/){
this.possiblyBroken = true;
}
// Notify anyone who's interested
if (this.possiblyBroken && (this.getConnectionHook() != null)){
this.possiblyBroken = this.getConnectionHook().onConnectionException(this, state, e);
}
根据这些代码,boneCP
当 SQLException 的状态等于“08001”、“08007”、“08S01”、“57P01”、“HY000”之一时,将其视为数据库服务器崩溃。
但是为什么,这些州代表什么?