Skip to content

Instantly share code, notes, and snippets.

@oehme
Created November 4, 2013 15:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oehme/7304164 to your computer and use it in GitHub Desktop.
Save oehme/7304164 to your computer and use it in GitHub Desktop.
Joda Time to JDBC - Working, but slow
private Calendar utc() {
return Calendar.getInstance(TimeZone.getTimeZone("UTC"));
}
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