![](/img/trans.png)
[英]Convert java.sql.Timestamp to Java 8 ZonedDateTime?
[英]Convert Timestamp from Database to java.sql.Timestamp
我正在从数据库查询数据,并想将数据库时间戳转换为java.sql.Timestamp:
List<Map<String, Object>> rows = jdbcTemplate.queryForList(SELECT_ALL_DATA);
for(Map row : rows) {
Customer customer = new Customer();
customer.setMaturityDate(new Timestamp((Long) row.get("MATURTIY_DATE")));
}
但是,这样做可以使我:
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: java.sql.Timestamp cannot be cast to java.lang.Long
我也尝试了一下,但没有强制转换为Long
,但这给了我:
The constructor Timestamp(Object) is undefined
有什么建议如何转换数据库对象?
感谢您的回复!
您无需创建新的时间戳实例,因为它已经返回了一个实例:
List<Map<String, Object>> rows = jdbcTemplate.queryForList(SELECT_ALL_DATA);
for(Map row : rows) {
Customer customer = new Customer();
customer.setMaturityDate((Timestamp)row.get("MATURTIY_DATE"));
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.