I have a query of inner join tables:
List<Object[]> resultList = entityManager.createNativeQuery(SOME QUERY).getResultList();
When i try to access the elements of Object[]
one of which is a Date
I tried doing this:
for(Object[] obj : resultList) {
Date createdDate = obj[7] !=null ? new Date(Long.valueOf(obj[7] + "")) : null;
}
This gave obvious exception:
nested exception is java.lang.NumberFormatException: For input string: "2012-11-20"
I changed the Date
to DateTime
get TO_CHAR(createdDate,'DD.MM.YYYY:HH24:MI:SS')
And tried the below code:
DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
Date createdDate = null;
try {
createdDate = df.parse(obj[7] + "");
} catch (ParseException e) {
e.printStackTrace();
}
This approach results: createdDate = null
Any Suggestions ?