Y
Y
Yu Yu2015-01-27 12:32:34
Java
Yu Yu, 2015-01-27 12:32:34

How to get date from database?

From the database I get a string with the date and time.
The string could be: 2015-01-25 16:26:08.34
ResultSet rs;
java.sql.Timestamp sqlts = rs.getTimestamp(index);
Then this date should be used in an external object (processing, sorting, etc.)
What and how to convert it better util.Date or util.Calendar?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikolai Pavlov, 2015-01-27
@gurinderu

Timestamp is a normal long.
Try this new Date(sqlts.getTime()).
In Java 8, Timestamp has toInstant() and toLocalDateTim() methods. You can try to use them.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question