0

I am querying data from a database and want to convert a Database Timestamp to a 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")));
    }

However, doing it like that gives me:

Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: java.sql.Timestamp cannot be cast to java.lang.Long

I also tried it without the cast to Long, but this gives me:

The constructor Timestamp(Object) is undefined

Any recommendations how to cast the database object?

I appreciate your reply!

0

1 Answer 1

1

You don't need to create a new timestamp instance because it is already returned one:

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"));
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.