同步釋出:http://www.yuanrengu.com/index.php/mysqlsolvetimestamp.html
在使用mysql時,如果資料庫中的欄位型別是timestamp,預設為0000-00-00,會發生異常:Value ‘0000-00-00 00:00:00’ can not be represented as java.sql.Timestamp.
解決辦法如下:
給資料庫的jdbc.url加上zeroDateTimeBehavior引數,如下:
jdbc.url=jdbc:mysql://localhost:3306/table?characterEncoding=UTF-8&zeroDateTimeBehavior=round
zeroDateTimeBehavior引數有兩種配置:
- zeroDateTimeBehavior=round ,”0000-00-00“會預設轉換為”0001-01-01 00:00:00”
- zeroDateTimeBehavior=convertToNull,“0000-00-00“會轉換為null