2013-09-25 2 views
0

저는 Ibatis를 처음 사용합니다. 나는 SQL 예외 및 오류 코드를 잡으려고하지만 그것을 찾을 수 없습니다. Ibatis 예외는 런타임 예외입니다. 그렇다면 어떻게 SQL 오류 메시지와 오류 코드를 찾을 수 있습니까?Ibatis에서 메시지 및 오류 코드가있는 SQLException을 얻는 방법

com.common.dao.BaseDaoImpl : 내가 잡을 예외는 다음과 같다 - 167 오류 코드 카테고리를 마스터 생성 캡처 : - ID [createMaster, parameterObject [com.mslkp.vo.msklpVO를 삽입 할 수 없습니다 @ a27b9e]. 원인 : com.ibatis.common.jdbc.exception.NestedSQLException :

--- com/sql/createMSLKP.xml에서 오류가 발생했습니다.

--- 매개 변수 맵을 적용하는 동안 오류가 발생했습니다.

--- createMSLKP-InlineParameterMap을 확인하십시오.

--- 성명을 확인하십시오 (업데이트 실패).

--- 원인 : java.sql.SQLIntegrityConstraintViolationException : ORA-01400 : (.. "MS" "T_MSTR_LKUP" "DELET_FLG을")에 NULL을 삽입 할 수 없습니다

가 어떻게 잡을 않는 오류 코드 01400과 같은 ?

+2

잡아라'NestedSQLException' (가 또는 어떤 다른 포장 예외)을 얻을의 '원인 '. –

+0

Actualy com.ibatis.common.jdbc.exception.RuntimeSQLException뿐만 아니라 하위 클래스에는 getErrorCode() 메소드가 있습니다. 시도해보십시오. – Jk1

답변

0

캐치 iBATIS를 예외 및 원인의 체인을 통해 발굴, 당신이 가지고있는 오류 메시지가 어디 있는지 방법을 설명 :

} catch (RuntimeSQLException e) { 
    if (e.getCause() == null) { 
     throw e; // not what you're interested in, throw it back 
    } 
    Exception nested = e.getCause().getCause(); 
    if (nested instanceof SQLIntegrityConstraintViolationException) { 
     SQLIntegrityConstraintViolationException constraintViolation = (SQLIntegrityConstraintViolationException)nested; 
     String message = constraintViolation.getMessage(); 
     String sqlState = constraintViolation.getSQLState(); 
     int errorCode = constraintViolation.getErrorCode(); 
     // create validation message or whatever 
    } else { 
     throw e; // not what you're interested in, throw it back 
    } 
}