Hibernate 时间查询错误

来源:互联网 发布:c语言abs函数 编辑:程序博客网 时间:2024/05/28 16:01

1、错误Timestamp format must be yyyy-mm-dd hh:mm:ss[.fffffffff]
在hibernate连接数据查询的时候,Date类型的数据在查询的时候需要转为Timestamp类型。

2、错误’0000-00-00 00:00:00’ can not be represented as java.sql.Timestamp
出现这种错误是因为数据库中对应的字段值为空

3、String 类型转为Date类型
Date beginDate = sdf.parse(“2017-08-01 00:30:00”);

SimpleDateFormat format = new SimpleDateFormat(“yyyy-MM-dd HH:mm:ss”);
/将Date格式化/
String sdate = format.format(beginDate);
/将String 转为转为Timestamp 类型/
Timestamp sTimestamp = Timestamp.valueOf(sdate);

原创粉丝点击