This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Java in General and the fly likes need to send java.util.Date to database with date AND time (so cannot use java.sql.Date) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "need to send java.util.Date to database with date AND time (so cannot use java.sql.Date)" Watch "need to send java.util.Date to database with date AND time (so cannot use java.sql.Date)" New topic
Author

need to send java.util.Date to database with date AND time (so cannot use java.sql.Date)

Matt Kohanek
Village Idiot
Ranch Hand

Joined: Apr 04, 2009
Posts: 483

I got some help with this yesterday before I was able to do any testing. It was suggested I use java.sql.Timestamp
However, now that I have had time to try that out, I get the following
java.util.Date cannot be cast to java.sql.Timestamp

So that is not going to work. Is there some other type I can use, or is there a way to convert between the two?

Thanks


True wisdom is in knowing you know nothing - Socrates
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3506
    
  14
Matt Kohanek wrote:I got some help with this yesterday before I was able to do any testing. It was suggested I use java.sql.Timestamp
However, now that I have had time to try that out, I get the following
java.util.Date cannot be cast to java.sql.Timestamp

So that is not going to work. Is there some other type I can use, or is there a way to convert between the two?

Thanks

You can't cast a java.util.Date to a java.sql.Timestamp, but you can create a java.sql.Timestamp using a java.util.Date. Take a look at the javadoc.


Joanne
Matt Kohanek
Village Idiot
Ranch Hand

Joined: Apr 04, 2009
Posts: 483

Ah, yes, of course, the answer was, 'you are a dummy Matt' :p

Thanks
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3506
    
  14
Matt Kohanek wrote:Ah, yes, of course, the answer was, 'you are a dummy Matt' :p

Thanks

I'm sure you were just demonstrating that your title was well earned.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: need to send java.util.Date to database with date AND time (so cannot use java.sql.Date)