2013-04-15 4 views
4

executeInsert()과 대조적으로 executeUpdate()을 사용하는 것의 차이점을 생각해 봤습니다. java.lang.RuntimeException가 : TypeDoesNotMatch (2013년 4월 15일 13 변환 할 수 없습니다 : 58 : 46.0 : 클래스 자바를 다음 코드에서Anorm Scala executeUpdate와 executeInsert의 차이점

, 나는

def addEntry(day: DateMidnight, create_time: DateTime, points: Long, src: String) = DB.withTransaction { implicit connection => 

    Logger.debug("I got here") 
    SQL(
     """ 
     INSERT INTO density_cache(day_of, create_time, points, src) 
      VALUES ({day_of}, {create_time}, {points}, {src}) 
     """ 
    ).on(
     'day_of  -> day, 
     'create_time -> create_time, 
     'points  -> points, 
     'src   -> src 
    ).executeInsert() 
    Logger.debug("Got to 2nd step") 
} 

나는 다음과 같은 문제를 얻을 executeInsert()을 사용했다. sql.Timestamp Long ColumnName (density_cache.day_of, Some (day_of))에 대한

그러나 내가 executeUpdate()로 전환하면 제대로 작동합니다.

답변

3

executeInsert은 자동 생성 키 (있는 경우)를 반환합니다.

Anorm, simple SQL data access => Executing SQL queries

당신이 자동 생성 Long 기본 키가 데이터를 삽입하는 경우 executeInsert()를 호출 할 수 있습니다. 생성 된 키가 둘 이상이거나 Long이 아닌 경우 executeInsertResultSetParser을 전달하여 올바른 키를 반환 할 수 있습니다.

귀하의 경우에는 자동 증가 기본 키가 없으므로 executeInsert()과 작동하지 않는다고 가정합니다. 그런 다음 올바른 유형의 ResultSetParser을 전달해야 할 수 있습니다.

관련 문제