Posted by joeNOSPAM@BEA.com on 02/09/07 01:00
On Feb 8, 2:32 pm, "MackTheKnife" <wgblack...@yahoo.com> wrote:
> Hi,
> I'm trying to write a java.sql.Date to a database and the minutes/
> seconds etc. are not being written. I've seen and tested many
> examples
> found via searches and still have come up with nothing. Here's what I
> have:
>
> java.sql.Date formation - recommended constructor forms:
> java.sql.Date entryDttm = new
> java.sql.Date(System.currentTimeMillis());
> OR
> java.sql.Date entryDttm = new java.sql.Date(new
> java.util.Date().getTime());
>
> // prepared statement insert
> pstmt.setDate(1, entryDttm);
> // what is written to database
> 2007-02-07 12:00:00.000
>
> // what needs to be written
> 2007-02-08 09:37:25.793
>
> The above date value is written when I insert using the SQL method
> GETDATE()
>
> The field is stored in a MS SQL Server 8.0 database and is defined as
> a 'datatime' or 'smalldatetime' field.
>
> How can I replicate the results of GETDATE() into 'datetime' and
> 'smalldatetime' fields in
> a MS-SQL Server database (or is it possible?). Would a timestamp
> datatype make more sense?
>
> I'm using MS_SQL Server JDBC drivers.
>
> Any advice would be GREATLY appreciated!
Hi. You should instead construct a java.sql.Timestamp and send it via
setTimestamp(). A java.sql.Date is a *date*. The time portion is
normalized
to zero.
Joe Weinstein at BEA Systems
[Back to original message]
|