我試圖做一個JDBC
連接池組件,但遇到了問題。即:如何檢測java.sql.SQLException
的錯誤狀態。 據說國家應該遵循SQL2003
公約和XOPEN SQL
公約JDK
文件。但是我找不到任何有關這兩個約定的文件。有人可以爲我提供嗎?如何檢測SQLException的SQL錯誤狀態
我想知道每個國家代表什麼,所以我可以決定何時完全關閉連接或重新連接。
我已經提到BoneCP
的源代碼。下面是一個零件時SQLException的發生將被actived:
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「。
但是爲什麼這些國家代表什麼?
任何特殊功能或理由發展,而不是使用任何堅固的連接池庫? – Scorpion
只是一種有趣的獲得我的技能提升。 –