wood burning stoves 2.0*
The moose likes Distributed Java and the fly likes how to cast the java.util.date to java.sql.date Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Distributed Java
Bookmark "how to cast the java.util.date to java.sql.date" Watch "how to cast the java.util.date to java.sql.date" New topic
Author

how to cast the java.util.date to java.sql.date

lei zhang
Greenhorn

Joined: Sep 15, 2004
Posts: 14
how to cast the java.util.date to java.sql.date

please give me a help!



and i want to get the hours,seconds.


people laugh and people cry.some give up some always try.some say hi while some say bye.others may forget you but never i!!
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41116
    
  45
java.sql.Date extends java.util.Date. That means you can cast java.sql.Date to java.util.Date, but not the other way round.

Both classes have methods called getHours, getMinutes and getSeconds.


Ping & DNS - my free Android networking tools app
Abhijith Prabhakar
Ranch Hand

Joined: Dec 29, 2006
Posts: 56
Hope this helps

/**
* Returns the sql.Date for the given util.Date
*
* @param oDate util.Date object
* @return sql.Date
*/
public static java.sql.Date convertToSqlDate(java.util.Date oDate) {
return (new java.sql.Date(oDate.getTime()));
}

/**
* Returns the util.Date for the given sql.Date
*
* @param sqlDate sql.Date object
* @return util.Date
*/
public static java.util.Date convertToDate(java.sql.Date sqlDate) {
return (new java.util.Date(sqlDate.getTime()));
}
lei zhang
Greenhorn

Joined: Sep 15, 2004
Posts: 14
reply Abhijith Prabhakar :

thank you give me the methods to deal with this,but ,i do it like you say that,but i translate it in this way what you say,i didn't get the hours,minutes,and seconds only the day,month,and year ,can you tell me why?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41116
    
  45
What do you mean by "i didn't get the hours,minutes,and seconds"? The getHours, getMinutes and getSeconds methods must return something. If you mean that the return value is always zero, have you checked that the DB has the exact values for those fields?
 
 
subject: how to cast the java.util.date to java.sql.date
 
Similar Threads
java.sql.date
comparing date fields from a database
Using CacheRowset
java.util.Date,java.Sql.Date
populating the databse