I am getting an exception when I try to format the date which is in oracle.sql.TIMESTAMP
. How can format this?
When I try to retrieve the date from the database, I am using the groovy to get the data:
Groovy doc but it doesn't have anything particular to date
// Part of the code
SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss:SSS")
def sql = new Sql(dataSource)
sql.eachRow('''select dateCreated from User'''){
row->
def dateCreated
if(row.dateCreated != null){ // I am getting the object as oracle.sql.TIMESTAMP.
dateCreated= df.format(row.dateCreated)
}
}
I am getting the exception like this .
2015-11-05 14:22:33,755 [http-8083-3] ERROR errors.GrailsExceptionResolver - Exception occurred when processing request: [GET] /getUsers - parameters: _dc: 1446713474579
Stacktrace follows:
java.lang.IllegalArgumentException: Cannot format given Object as a Date
at java.text.DateFormat.format(DateFormat.java:281)
at java.text.Format.format(Format.java:140)
at java_text_Format$format.call(Unknown Source)
at com.test.AdminController$_closure15_closure80.doCall(AdminController.groovy:953)
at $Proxy76.eachRow(Unknown Source)
at com.test.AdminController$_closure15.doCall(AdminController.groovy:941)
at com.test.AdminController$_closure15.doCall(AdminController.groovy)
at com.test.SecureController.invokeMethod(SecureController.groovy)
at com.test.AdminController$_closure21.doCall(AdminController.groovy:1061)
at com.test.AdminController$_closure21.doCall(AdminController.groovy)
at org.grails.jaxrs.web.JaxrsFilter.doFilterInternal(JaxrsFilter.java:46)
at java.lang.Thread.run(Thread.java:662)