Error attempting to get column ‘birthday‘ from result set. Cause: java.sql.SQLException: HOUR_OF_DA

1. Problems encountered

 2. Reason: 

        Caused by daylight saving time. Only 1940-06-03, 1941-03-16, 1986-05-04, 1987-04-12, 1988-04-10, 1989-04-16, 1990-04-15, 1991-04-14 Time will throw the above error    

3. Try to solve    

        (1) Add &serverTimezone=GMT%2B8 after the jdbc connection, do not use &serverTimezone=Asia/Shanghai

        (2) Change java.util.Date to java.sql.Date

1.按照第一篇和其他网上的说法,已经确实设置了时区serverTimezone=Asia/Shanghai
2.尝试过将Date改为LocalDate,但是业务上行不通,数据最后需要转为格式化yyyy-MM-dd HH:mm:ss,用fastjson和jacksjon都没有办法转为这种格式。转出来的数据不是序列化不对,就是转成了一个分段的json对象。

最后根据看到日志中Date class是java.util.Date, 想到java.sql.Date这个类,按照原来的经验这个类是会处理一些特殊的情况。
比如 数据库表 create _time  字段为 timestamp 类型,要用java.sql. Timestamp 来接收。

But it's not ideal, I'm trying other methods

4. Solution

数据库表 birthday  字段为 datetime类型

实体类为
@JsonFormat(pattern = "yyyy-MM-dd")
@Excel(name = "出生日期", width = 30, dateFormat = "yyyy-MM-dd")
private Date birthday;

If the interface is requested again, no error will be reported.

Guess you like

Origin blog.csdn.net/weixin_51906670/article/details/130556793