http://grepcode.com/file/repo1.maven.org/maven2/com.payneteasy/mysql-scheduler/1.0-4/org/springframework/jdbc/support/sql-error-codes.xml
public int insertChannel(ChannelVO channelParam) throws DataAccessException {
try {
return (int) sqlMapClientTemplate.update(namespace +".insertChannel", channelParam);
} catch (DataAccessException e) {
// 1. Error Code를 취득해 예외처리
SQLException se = (SQLException) e.getRootCause();
System.out.println("Error Code : " + se.getErrorCode());
// 2. 또는 Exception을 구분해 예외처리
if(e instanceof DataIntegrityViolationException){
System.out.println("무결성 제약 조건 위반");
}else if (e instanceof BadSqlGrammarException){
System.out.println("SQL이 유효하지 않은 경우 예외가 발생");
}else if(e instanceof DataAccessResourceFailureException){ //
System.out.println("JDBC를 사용하여 데이터베이스에 연결할 수 없는경우");
}else if(e instanceof CannotAcquireLockException){
System.out.println("누군가 DB물고있는경우, 누가 커밋안했을때 - DB락");
}else if(e instanceof DeadlockLoserDataAccessException){
System.out.println("현재 프로세스가 교착 상태");
}
SQLException se = (SQLException) e.getRootCause();
System.out.println("##########################");
System.out.println(se.getErrorCode());
System.out.println("##########################");
throw e;
}
}
----------------------------------------------------------------------------
* 스프링프레임워크 내 sql-error-codes.xml파일
<bean id="MySQL" class="org.springframework.jdbc.support.SQLErrorCodes">
<property name="badSqlGrammarCodes">
<value>1054,1064,1146</value>
</property>
<property name="dataAccessResourceFailureCodes">
<value>1</value>
</property>
<property name="dataIntegrityViolationCodes">
<value>1062</value>
</property>
<property name="cannotAcquireLockCodes">
<value>1205</value>
</property>
<property name="deadlockLoserCodes">
<value>1213</value>
</property>
</bean>
<bean id="Oracle" class="org.springframework.jdbc.support.SQLErrorCodes">
<property name="badSqlGrammarCodes">
<value>900,903,904,917,936,942,17006</value>
</property>
<property name="invalidResultSetAccessCodes">
<value>17003</value>
</property>
<property name="dataAccessResourceFailureCodes">
<value>17002,17447</value>
</property>
<property name="dataIntegrityViolationCodes">
<value>1,1400,1722,2291</value>
</property>
<property name="cannotAcquireLockCodes">
<value>54</value>
</property>
<property name="deadlockLoserCodes">
<value>60</value>
</property>
</bean>
'Back-End > Spring' 카테고리의 다른 글
log4sql (0) | 2018.02.08 |
---|---|
[Jasypt] jdbc.properties 접속정보 PBEWithMD5AndDES 암호화 2 (0) | 2015.04.21 |
Spring에서 SQL Exception 처리하기. (0) | 2014.03.05 |
@RequestParam - 1:1로 파라미터 집어넣기 (0) | 2012.09.11 |
@ModelAttribute - 파라메터 한번에 집어넣기 (0) | 2012.09.11 |