You are here: Re: Full date value not being written via JDBC - any ideas? « MsSQL Server « IT news, forums, messages
Re: Full date value not being written via JDBC - any ideas?

Posted by Erland Sommarskog on 02/08/07 23:20

MackTheKnife (wgblackmon@yahoo.com) writes:
> 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

Oh-oh. Since I don't know Java or JDBC, I don't have any idea of what
is going on. But use the Profiler to see what is sent to SQL Server.

> 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?

No, timestamp would not make any sense at all. This is an 8-byte
value that is automatically updated everytime the row is updated.
It has no relation to date and time.


--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация