How to use Joda-Time with java.sql.Timestamp
java, jodatime, postgresql, timestamp
Solution
You can convert a Joda DateTime to a long (millis since the epoch) first, and then create a Timestamp from that.
DateTime dateTime = new DateTime();
Timestamp timeStamp = new Timestamp(dateTime.getMillis());
Problem
I Have a prepared statement ``` INSERT INTO mst(time) VALUES (?); ``` where time is of type Timestamp in a PostgreSQL database. I am inserting a Joda-Time DateTime object, or I should say I am trying to. I can find no way to convert the DateTime object into a java.sql.Timestamp. I have read the Joda-Time docs and see no reference to this. Thanks.