잡담.
삽질의 연속
인터넷에도 퍼즐처럼 흩어져 있어서 하루종일 시블시블거리면서 찾은 정보.
## javaType을 설정하면 Null 값으로 나오는 데이터를 Java 타입에 맞게 Default 값으로 뽑아준다
## log Level이 debug이면, 17004 에러가 계속 발생한다. Info로 바꿀것.
1. mybatis-config > typeHandler 설정
<!-- 참고: Type Alias 보다 아래에 둘것 -->
2. SQL XML > resultMap 추가
- sql 부분
3. Handler 클래스 추가
@MappedJdbcTypes(JdbcType.LONGVARCHAR)
public class MyLongTypeHandler implements TypeHandler {
@Override
public void setParameter(PreparedStatement ps, int i, Object parameter, JdbcType jdbcType)
throws SQLException {
String s = (String) parameter;
StringReader reader = new StringReader(s);
ps.setCharacterStream(i, reader, s.length());
}
@Override
public Object getResult(ResultSet rs, String columnName) throws SQLException {
return rs.getString(columnName);
}
@Override
public Object getResult(CallableStatement cs, int columnIndex) throws SQLException {
return cs.getString(columnIndex);
}
}
4. 참조
- http://mybatis.github.io/mybatis-3/ko/configuration.html 의 typeHandlers 부분 참조
'Java & Spring > iBatis & myBatis' 카테고리의 다른 글
[iBatis] dynamic prepend (0) | 2015.10.20 |
---|---|
[iBatis] 리스트 타입의 데이터를 in 조건으로 만들기 (0) | 2015.10.20 |
[iBatis] 자바에서 만든쿼리를 실행하기 (0) | 2015.09.16 |
[iBatis] 프로시저 처리 (0) | 2015.09.14 |
[iBatis/myBatis] SELECT - INSERT를 할 때 (1) | 2015.09.09 |
WRITTEN BY