[서버][스프링] Caused by: org.h2.jdbc.JdbcSQLException: Cannot parse "TIMESTAMP" constant "0000-00-00 00:00:00"; SQL statement:

프로그래밍/서버2021. 3. 20. 16:36
Caused by: org.h2.jdbc.JdbcSQLException: Cannot parse "TIMESTAMP" constant "0000-00-00 00:00:00"; SQL statement:

 

JDBC가 TIMESTAMP 타입의 column에서 "0000-00-00 00:00:00"인 값을 파싱하지 못해 생기는 문제입니다.

MySQL에서 datetime은 "0000-00-00 00:00:00" 값을 사용할 수 있지만

이에 매핑되는 자바의 LocalDateTime은 이를 사용할 수 없습니다.

 

0000년은 인식할 수 있는데 0월 0일이 문제인 것 같네요.

그렇다고 자바의 LocalDateTime에서 "0000-00-00 00:00:00"을 null로 처리하기도 애매합니다.

MySQL에서 null과 "0000-00-00 00:00:00"은 다른 값이니까요.

 

각자의 상황에 맞게 해결 방법이 다를 것 같습니다.

MySQL에서 해당 column의 기본값은 1970-01-01 00:00:00 등과 같이 지정하는 것도 쉬운 해결 방법 같네요.

 

 

참고

stackoverflow.com/questions/11133759/0000-00-00-000000-can-not-be-represented-as-java-sql-timestamp-error

 

'0000-00-00 00:00:00' can not be represented as java.sql.Timestamp error

I have a database table containing dates (`date` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00'). I'm using MySQL. From the program sometimes data is passed without the date to the database....

stackoverflow.com

stackoverflow.com/questions/782823/handling-datetime-values-0000-00-00-000000-in-jdbc/1180131

 

handling DATETIME values 0000-00-00 00:00:00 in JDBC

I get an exception (see below) if I try to do resultset.getString("add_date"); for a JDBC connection to a MySQL database containing a DATETIME value of 0000-00-00 00:00:00 (the quasi-null value ...

stackoverflow.com

docs.oracle.com/javase/8/docs/api/java/time/LocalDateTime.html

 

LocalDateTime (Java Platform SE 8 )

Returns a copy of this date-time with the specified field set to a new value. This returns a LocalDateTime, based on this one, with the value for the specified field changed. This can be used to change any supported field, such as the year, month or day-of

docs.oracle.com

stackoverflow.com/questions/59800273/how-to-set-time-0000-00-00-000000-to-localdatetime

 

How to set time "0000-00-00 00:00:00" to LocalDateTime?

To write test I need to set LocalDateTimeto 0000-00-00 00:00:00. When I try to set it using formatter: DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); LocalDateTime.

stackoverflow.com

 

작성자

Posted by 드리머즈

관련 글

댓글 영역