1

こんにちは。私のdaoではSpring DataAccessExceptionの翻訳機構が使えないようなので、翻訳できるか知りたいです。

Internal Exception: java.sql.SQLException: [BEA][Oracle JDBC Driver][Oracle]ORA-00001: unique constraint (JSP_OWN.IDX_MC_CC_RAPPORTI_02) violated

DataAccessException 階層に手動で追加します。

よろしくマッシモ

4

1 に答える 1

1

あなたが持っているならJdbcTemplate、あなたはすることができます

catch (SqlException e) {
  throw jdbcTemplate.getExceptionTranslator().translate("my task", null, e);
}

を持っていない場合JdbcTemplateは、JdbcTemplate.getExceptionTranslator()メソッドのソース コードを見てください。

public synchronized SQLExceptionTranslator getExceptionTranslator() {
    if (this.exceptionTranslator == null) {
        DataSource dataSource = getDataSource();
        if (dataSource != null) {
            this.exceptionTranslator = new SQLErrorCodeSQLExceptionTranslator(dataSource);
        }
        else {
            this.exceptionTranslator = new SQLStateSQLExceptionTranslator();
        }
    }
    return this.exceptionTranslator;
}

そして、その動作を模倣します:-)

于 2012-01-11T09:11:27.093 に答える