- 전체
- JAVA 일반
- JAVA 수학
- JAVA 그래픽
- JAVA 자료구조
- JAVA 인공지능
- JAVA 인터넷
- Java Framework
- Java GUI (AWT,SWING,SWT,JFACE)
- SWT and RCP (web RAP/RWT)[eclipse], EMF
JAVA 자료구조 MyBatis 에서 출력하는 에러 보기 : Catch exception in MyBatis
2018.08.22 17:52
MyBatis 에서 출력하는 에러 보기 :
Catch exception in MyBatis 2016-07-04 04:16
I generate mapper interface and xml file in my application. There is no exception in method signature. But when the sql execute failed MyBatis will throw an exception. I found the exception thrown from MyBatis is always PersistenceException. After reading the source code, I seemed to understand.
DefaultSqlSession
public int update(String statement, Object parameter) {
try {
dirty = true;
MappedStatement ms = configuration.getMappedStatement(statement);
return executor.update(ms, wrapCollection(parameter));
} catch (Exception e) {
throw ExceptionFactory.wrapException("Error updating database. Cause: " + e, e);
} finally {
ErrorContext.instance().reset();
}
}
ExceptionFactory
public class ExceptionFactory {
public static RuntimeException wrapException(String message, Exception e) {
return new PersistenceException(ErrorContext.instance().message(message).cause(e).toString(), e);
}
}
If you want catch the exception in MyBatis you can capture the PersistenceException. Do not forget that it wraps the real exception. Capture exception code may like following.
try {
// invoke mapper
} catch (PersistenceException e) {
final Throwable cause = e.getCause();
if (cause instanceof PSQLException) {
// handle the exception
}
}
[출처] http://www.henryxi.com/catch-exception-in-mybatis
본 웹사이트는 광고를 포함하고 있습니다.
광고 클릭에서 발생하는 수익금은 모두 웹사이트 서버의 유지 및 관리, 그리고 기술 콘텐츠 향상을 위해 쓰여집니다.
광고 클릭에서 발생하는 수익금은 모두 웹사이트 서버의 유지 및 관리, 그리고 기술 콘텐츠 향상을 위해 쓰여집니다.
댓글 0
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 수 |
|---|---|---|---|---|
| 1 |
numerical analysis with java examples - turhancoban.com.pdf
| 졸리운_곰 | 2016.06.07 | 512 |

