當數據庫連接問題發生時,如數據庫服務器關閉而不是SQL問題,我需要做一個特殊處理。如何判斷何時存在連接數據庫問題?
在源代碼中,我們可以得到各種例外,但哪些屬於連接?
我們希望如果出現這種問題會減少日誌。
EDITED
我有執行連接到數據庫,但都得到了同樣的方法(initSession)會議許多方法: 下面的例子:
private Session initSession(HibernateUtil hibernateUtil) {
Session oSession = null;
try {
oSession = hibernateUtil.getSession();
} catch (Exception e) {
log.error("unable to log, Please check the details of your database");
}
return oSession;
}
public List findAlerts(int pFirstLine, int pNbElement) throws AnalyzerException {
List oAlerts = new ArrayList();
Session oSession = initSession(lHibernateUtil);
try {
oAlerts = AlertFinders.instance().findAlertByStatus(oSession, false, pFirstLine, pNbElement);
Iterator iterAlerts = oAlerts.iterator();
while (iterAlerts.hasNext()) {
...
}
} catch (UnableToLocateObjectException eU) {
throw new AnalyzerException(eU.getMessageSource(), eU.getClassNameSource(), eU.getMethodSource(), eU);
} finally {
oSession.close();
}
return oAlerts;
}
請找上面 – kkung