Reputation: 1931
I have a java servlet that calls a method in a java class named OAVDbUtil.java to obtain a date from a SQL database. I can retrieve the date but not the complete value. In the SQL Server database the field is "EventTime" and is a datetime field and an example of the date data is;
2015-02-16 11:48:15.730
In OAVDbUtil.java I have the code to retrieve the value in a results set and place it in a variable like this, where Date is of type java.sql.Date
Date loginDate = myRs.getDate("EventTime");
But it retrieves the data as "2015-02-16". How do I retrieve the date as "2015-02-16 11:48:15.730"?
Upvotes: 1
Views: 2598
Reputation: 1444
Use getTimestamp:
Timestamp loginDate = myRs.getTimestamp("EventTime");
Use SimpleDateFormat to convert it to a String.
Upvotes: 0
Reputation: 7406
It's confusing, but important to note that, unlike java.util.Date
, java.sql.Date
really is just the date. The time-of-day is not included.
For what you want, you should use a java.sql.Timestamp
.
Upvotes: 3