Skip to content

Instantly share code, notes, and snippets.

@oehme
Last active December 27, 2015 09:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oehme/7304237 to your computer and use it in GitHub Desktop.
Save oehme/7304237 to your computer and use it in GitHub Desktop.
Joda Time to JDBC - working and fast
private static final Calendar UTC = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
private Calendar utc() {
return (Calendar) UTC.clone();
}
//unchanged
public LocalDateTime getValue(ResultSet rs, int index) throws SQLException {
Timestamp ts = rs.getTimestamp(index, utc());
return ts != null ? new LocalDateTime(ts.getTime(), DateTimeZone.UTC) : null;
}
public void setValue(PreparedStatement st, int index, LocalDateTime value) throws SQLException {
DateTime dt = value.toDateTime(DateTimeZone.UTC);
st.setTimestamp(index, new Timestamp(dt.getMillis()), utc());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment