views:

1433

answers:

1

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 DateTime object, or I should say I am trying to. I can find no way to convert the DateTime ovject into a java.sql.Timestamp. I have read the Joda docs and see no reference to this.

Thanks.

+7  A: 

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());
Jack Leow
Where about the TimeZone component ? You have only "copied" the date and time but not the timezone which can affect the actual value...
mP
Could you elaborate on what you mean? dateTime.getMillis() returns the milliseconds since epoch, which takes timezone into account.
Jack Leow