in database my column is of type TIMESTAMP, so my class has properties of type Datetime like this:
public void setDiscoveryDate(final DateTime discoveryDtTm) {
this.discoveryDtTm = discoveryDtTm;
}
now in JdbcTemplate I want to get it, so some code like this:
variant.setDiscoveryDate(rs.getTimestamp("discovery_dt_tm"));
which does Not work because column the get for resultset I could not find something that returns DateTime, I only saw either getDate or getTime.
That’s because
DateTimeis not a standard Java type. If you’re referring to the JodaTime type, then try this:This will break if
rs.getTimestampreturnsnull, so you may want to break this up into smaller statements and add checks fornull.Note that this can be made easier, since
DateTime‘s constructor takes ajava.util.Date, whichTimestampis a subclass of:But it’s also wrong, due to bad design of the
Timestampclass (see javadoc for explanation).Stick with the first example (with
getTime())