I have a Date field in Oracle DB.
Date field1
Now there is a existing DAO that fetches this field1 in form of Object
Object field1
Now I need to typeCast it to java Date
But if i do like following i get error:
Date dt = (Date) object; //object holds date object
DateTime jdt = new DateTime(dt) ; //convert it to jodaDate
Error : cannot cast Long to Date.
How to convert it to javaDate and than Joda DateTime
You are confusing the datatype
DATEin the Oracle DB with the Java typeDate. The errorcannot cast Long to Datestates that the object you are holding is of the Java typeLong, which is why the cast to the JavaDatetype fails. The Long represents the number of seconds or miliseconds since 01/01/1970, depending on yor DOA layer (see it’s documentation), since the DATE precision in Oracle only goes down to seconds. To receive a date, usenew Date((long) object)ornew Date(1000 * (long) object)respectively.You also can use those number of milliseconds to generate a
DateTimedirectly without using the JavaDateclass at all.