1. 程式人生 > >報錯java.sql.SQLException: Value '0000-00-00 00:00:00' can not be represented as java.sql.Timestamp

報錯java.sql.SQLException: Value '0000-00-00 00:00:00' can not be represented as java.sql.Timestamp

報錯環境是maraiadb5.5所用的時間欄位是timestamp,mariadb5.6用的datetime的mariadb是不會報這個錯誤的
在這裡插入圖片描述
原配置為:
spring.datasource.url=jdbc:mysql://10.44.100.217:3306/xxx_test?autoReconnect=true&useSSL=false&allowMultiQueries=true
修改後配置為:
spring.datasource.url=jdbc:mysql://10.44.100.217:3306/xxx_test?autoReconnect=true&useSSL=false&allowMultiQueries=true&zeroDateTimeBehavior=convertToNull
這類異常的發生和所用欄位型別timestamp有關係,後加zeroDateTimeBehavior=convertToNull是將為0的時間型別以null的方式傳輸