将时间戳从数据库转换为java.sql.Timestamp
我正在查询数据库中的数据,希望将数据库时间戳转换为java.sql.Timestamp:将时间戳从数据库转换为java.sql.Timestamp,java,database,timestamp,Java,Database,Timestamp,我正在查询数据库中的数据,希望将数据库时间戳转换为java.sql.Timestamp: List<Map<String, Object>> rows = jdbcTemplate.queryForList(SELECT_ALL_DATA); for(Map row : rows) { Customer customer = new Customer(); customer.setMa
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")));
}
我也尝试了它,但没有将其转换为Long
,但这给了我:
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: java.sql.Timestamp cannot be cast to java.lang.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"));
}
List rows=jdbcTemplate.queryForList(选择所有数据);
用于(地图行:行){
客户=新客户();
customer.setMaturityDate((时间戳)row.get(“MATURTIY_DATE”);
}