336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.
Slick 으로 DB CRUD 를 해보고 있는데
DateTime 을 읽을 때 아래와 같은 오류가 난다.
java.time.format.DateTimeParseException: Text '2019-07-24 00:00:00' could not be parsed at index 10
"scala slick date" 키워드로 구글링 검색 결과, Slick 3.3.2 Upgrade Guide 가 나온다. 일단 들어가본다
https://scala-slick.org/doc/3.3.2/upgrade.html
사용중인 DBMS 는 mySQL.
Upgrade Guide 의 slick.jdbc.MySQLProfile 부분에 보면 DateTime -> LocalDateTime 으로 Parsing 될 때
어떤 타입의 Texts를 읽는지 나온다.
java.time.LocalDateTime TEXT '2019-02-03T18:20:28.661'
즉 yyyy-mm-dd'T'hh:MM:ss 형태로 있어야 하는데, T 가 없어 10번째 인덱스를 로딩하는중에 에러가 났던 것.
DB 를 바꾸긴 힘들고, Slick 로딩부분을 수정할 방법을 찾는다.
Upgrade Guide 에서 제공하는 링크를 참고하여 코드 수정 시작
(참고 : https://github.com/d6y/instant-etc/blob/master/src/main/scala/main.scala#L9-L45)
import java.sql.ResultSet
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
trait NewMySQLProfile extends slick.jdbc.JdbcProfile with slick.jdbc.MySQLProfile {
override val columnTypes = new JdbcTypes
class JdbcTypes extends super.JdbcTypes {
override val localDateTimeType : LocalDateTimeJdbcType = new LocalDateTimeJdbcType {
override def getValue(r: ResultSet, idx: Int) : LocalDateTime = {
val pattern = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
r.getString(idx) match {
case null => null
case iso8601String => LocalDateTime.parse(iso8601String, pattern) }
}
}
}
}
object NewMySQLProfile extends NewMySQLProfile
코드는 전부 올려두었으니, 분석은 이거 읽는분이 알아서...
그리고 Slick 의 코드에
import slick.jdbc.MySQLProfile.api._
이 부분을
import NewMySQLProfile.api._
로 바꾸면 된다. 패키지 & 클래스명은 자기의 패키지에 맞게 수정하시길.