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

OffsetDateTimeLocalDateTime多了时区信息,比如+8时区。

Views: 776 · Posted: 2024-04-18

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb/LiteNote

扫描下方二维码关注公众号和小程序↓↓↓

扫描下方二维码关注公众号和小程序↓↓↓


Today On History
Browsing Refresh