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);
本文主要探讨了在使用Hibernate框架进行数据库操作时遇到的日期类型转换错误,包括Timestamp格式问题及空值处理,并介绍了如何将String类型转换为Date类型及Timestamp类型的解决方案。

3万+

被折叠的 条评论
为什么被折叠?



