2012-06-29 2 views
-1

내 테이블 정의에 int 데이터 형식의 열이 있습니다. 값이 "0"이면 jdbcTemplate 업데이트 메소드가 기본적으로 "NULL"대신 "NULL"로이 필드를 업데이트해야합니다. Point Curingnot NULLSpring JDBCTemplate 업데이트 문제

this.jdbcTemplate.update("UPDATE GCUR_OBSERVATION " 
       + "SET ObserverId = ?," + "ObservationDate = ?," 
       + "PointCuring = ?" 
       + " WHERE locationId = ? AND ObservationStatus = 0", 
       new Object[] { new Integer(newObservation.getObserverId()), 
         newObservation.getObservationDate(), 
         new Integer(newObservation.getLocationId()) }); 

는 코드는 위의 잘 실행됩니다. 그러나 데이터베이스 테이블에 NULL으로 어떻게 저장할 수 있습니까?

답변

3

NUll 포인터 예외가 발생했기를 바랍니다.

Integer locId = null; 

if(newObservation.getLocationId() != null) { 
locId = new Integer(newObservation.getLocationId()); 
if(locId == 0) { 
    locId = null; 
} 
} 

시도 그리고 지금 여기 locId 패스.

this.jdbcTemplate.update("UPDATE GCUR_OBSERVATION " 
       + "SET ObserverId = ?," + "ObservationDate = ?," 
       + "PointCuring = ?" 
       + " WHERE locationId = ? AND ObservationStatus = 0", 
       new Object[] { new Integer(newObservation.getObserverId()), 
         newObservation.getObservationDate(), 
         locId) }); 
1

getLocationId()의 리턴 유형을 int로 가정하면 아래 코드가 작동합니다. getLocationId()의 시그니처를 Integer로 변경하고 초기화하는 코드가 0 대신 NULL로 설정되도록하십시오.

관련 문제