Spring Boot MyBatis PostgreSQL Cannot convert the column of type TIMESTAMPTZ to requested type java.time.LocalDateTime
Spring Boot MyBatis PostgreSQL About 1,008 words错误信息
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed: org.springframework.jdbc.BadSqlGrammarException: Error attempting to get column 'create_ts' from result set. Cause: org.postgresql.util.PSQLException: Cannot convert the column of type TIMESTAMPTZ to requested type java.time.LocalDateTime.
; bad SQL grammar []] with root cause
org.postgresql.util.PSQLException: Cannot convert the column of type TIMESTAMPTZ to requested type java.time.LocalDateTime.
at org.postgresql.jdbc.PgResultSet.getLocalDateTime(PgResultSet.java:727)
at org.postgresql.jdbc.PgResultSet.getObject(PgResultSet.java:3859)
at org.postgresql.jdbc.PgResultSet.getObject(PgResultSet.java:3879)
at com.zaxxer.hikari.pool.HikariProxyResultSet.getObject(HikariProxyResultSet.java)
错误原因
无法将PostgreSQL
中的timestamptz
转为Java
中的LocalDateTime
。
解决方法
将timestamptz
类型的字段转为OffsetDateTime
即可。
OffsetDateTime vs LocalDateTime
OffsetDateTime
比LocalDateTime
多了时区信息,比如+8
时区。
Views: 1,520 · Posted: 2024-04-18
————        END        ————
Give me a Star, Thanks:)
https://github.com/fendoudebb/LiteNote扫描下方二维码关注公众号和小程序↓↓↓
Loading...