In my database, I have a column type开发者_如何学Python : datetime.
Column data example : 2009-02-03 19:04:23.0I'm using : SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S");
to define my date format.
I'm using groovySQL to read tables and for each rows, I'm adding a new SampleJ object (mapped to a new table - SampleJ).
Here my closure :
def sampleQuery(int dataset) {
sqlModule.eachRow("""
select b.*
from dataset a, array_data b
where dataset_id = "${dataset}"
and a.array_data_id = b.array_data_id ;""")
{
def addSample= new SampleJ(it.toRowResult())
addSample.id = "${it.array_data_id}" as int
addSample.dateCreated = dateFormat.parse("${it.date_created}")
//addSample...(more columns)
addSample.save()
}
}
When I check, my temporary table "SampleJ", all my date does not match with "${it.date_created}".
All dates are set to "new Date()" (to closure execution time).Via debugger :
"${it.date_created}" is define as "Tue Feb 03 19:04:23 CST 2009", corresponding to (2009-02-03 19:04:23.0). I should have this date !How can I fix this issue ? I have no error, just wrong dates.
Is there an easy way to define my dates in SampleJ ? An alternative to addSample.dateCreated = dateFormat.parse("${it.date_created}") ?Grails will be setting date_created to the current time by convention, you need to add
static mapping = {
autoTimestamp false
}
to SampleJ.
Alternatively, rename dateCreated to something else.
精彩评论