I’m trying to write date information use a Spring 3 JdbcTemplate. I have something like the following:
public void foo(DateMidnight date){
jdbcTemplate().update(sql,date);
}
If date was a java.util.Date, this would be fine, but With a DateMidnight, this blows up. I could of course instead do:
public void foo(DateMidnight date){
jdbcTemplate().update(sql,date.toDate());
}
But it’s easy to forget to do this. Is there a way to tell Spring (3) that whenever a JdbcTemplate gets a DateMidnight (or DateTime), that it should convert that to a Date before storing? I read about the conversion service API, but from the code examples I’ve seen it only applies to converting in Spring MVC.
As far as I understand you need to override
JdbcTemplate.newArgPreparedStatementSetter()and implement appropriate conversion there, something like this: