私の struts2 webapp は SQL データベースを利用します。DB アクセス コード内に、SQL または一般的な例外をキャッチし、詳細をログ ファイルに書き込み、続行する基本的な try/catch ハンドラーを記述しました。クラスの階層は次のとおりです。
アクションメソッド -> モデルの get または set メソッド -> DB アクセス。
//Action method in action class
public string doActionMethod() throws Exception
{
String results = SampleModel.getResults();
}
//Model method in model class
public string getResults() throws Exception
{
String results = DBLayer.runQuery("SELECT Results FROM SampleTable WHERE Value='1');
}
//Method that queries database in DB access class
public string runQuery() throws Exception
{
ResultSet rs = null;
Connection dbConnection = null;
PreparedStatement preparedStatement = null;
dbConnection = MSSQLConnection.getConnection();
preparedStatement = dbConnection.prepareStatement(sqlQuery);
//run SQL statements
return String(rs.get(0));
}
適切なエラー ページに転送できるように、キャッチされた例外をアクション レベルまでバブルアップしたいと考えています。メソッド署名に「スロー例外」を追加するよりも良い方法はありますか?