File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes Regarding Datetime datatype Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Regarding Datetime datatype" Watch "Regarding Datetime datatype" New topic
Author

Regarding Datetime datatype

Vivek Alampally
Ranch Hand

Joined: Jul 10, 2008
Posts: 67
Hi
I am reading a Datetime datatype column from SQL server table. For some reason it is not printing hours, minutes seconds. How can I make my program to print hours, minutes seconds also.

Date s = resultset.getDate("last_modified_time"); // where last_modified_time is name of Datetime datatype column
System.out.println(s);

Thanks
Vivek
Tom Reilly
Rancher

Joined: Jun 01, 2010
Posts: 618
Generally, if you want to change the way a date is displayed, you can use java.text.DateFormat. But I looked at the documentation for java.sql.Date. It says:
To conform with the definition of SQL DATE, the millisecond values wrapped by a java.sql.Date instance must be 'normalized' by setting the hours, minutes, seconds, and milliseconds to zero in the particular time zone with which the instance is associated.
I take this to mean that even if you use DateFormat, it will not provide the time value as you'd expect. Try using java.sql.Timestamp instead.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Regarding Datetime datatype
 
Similar Threads
ClassCaseException
java.sql.Date comparison
Date API
Conversion of Current Time In Milliseconds using XSLT
how to compare sql date