views:

46

answers:

1

I am using the Java Joda Time library, and have a date and time stored as an org.joda.time.DateTime object.

How can I reliably convert this DateTime object into a String that will be parsed correctly by SQL server (including timezone), such that I can use it in an INSERT SQL statement?

+1  A: 

Use java.sql.Timestamp with PreparedStatement#setTimestamp().

ps.setTimestamp(1, new Timestamp(dateTime.getMillis()));

Note that java.sql.Date stores only the date part, not the time part.

BalusC