您的位置:首页 > 产品设计 > UI/UE

Value '0000-00-00' can not be represented as java.sql.Date

2016-05-30 10:21 295 查看
java.sql.SQLException: Value ‘0000-00-00 00:00:00’ can not be represented as java.sql.Timestamp

问题描述, 在java应用程序中,数据表中有记录的time字段(属性为timestamp)其值为:“0000-00-00 00:00:00”

程序使用select 语句从中取数据时出现以下异常:

java.sql.SQLException:Value ‘0000-00-00’ can not be represented as java.sql.Date

这是因为 “0000-00-00 00:00:00”在mysql中是作为一个特殊值存在的,但是在Java中, java.sql.Date 会被视为 不合法的值,被JVM认为格式不正确。

解决办法:

在jdbc的url加上 zeroDateTimeBehavior参数:

jdbc:mysql://192.168.1.202:3306/com?autoReconnect=true&useUnicode=true&characterset=utf8mb4&zeroDateTimeBehavior=convertToNull
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: