0

私の 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));
}

適切なエラー ページに転送できるように、キャッチされた例外をアクション レベルまでバブルアップしたいと考えています。メソッド署名に「スロー例外」を追加するよりも良い方法はありますか?

4

1 に答える 1

1

回復の見込みがないため、アプリケーション固有のRuntimeException.

標準の Struts 2 宣言型例外処理を使用して、アプリを適切なエラー ページに移動します。

于 2012-09-09T22:13:48.293 に答える