This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes JDBC and the fly likes java.util.Date does it contain information about hours? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "java.util.Date does it contain information about hours?" Watch "java.util.Date does it contain information about hours?" New topic
Author

java.util.Date does it contain information about hours?

Tristan Van Poucke
Ranch Hand

Joined: Jun 30, 2008
Posts: 47
When I write a Date() object to my Mysql database, I get the date correct but not the exact time, I always get f.e 2008-07-05 00:00:00 or 2008-08-22 00:00:00 How can you make sure to get the exact hour,minute and second?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18167
    
    8

You could review the type of the column to see if it is the correct type to hold a timestamp. Or you could review the code that inserts into that table to see if it's inserting a timestamp correctly.

Post more information if those two hints don't get you anywhere.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19557
    
  16

There are three date/time types in JDBC:
- Date stores only the date part
- Time stores only the time part
- Timestamp stores both

So switch to Timestamp (if your backing field allows it).


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java.util.Date does it contain information about hours?
 
Similar Threads
string to date parsing ....
Timezone Conversion
Java Date formatting problem
SEVERE: BAD packet signature 200,SEVERE: Caught exception (java.lang.NullPointerException)
How do i format a string to date