dbTalk Databases Forums  

java.sql.Date value truncated using JDBC in MS-SQL Server

comp.databases comp.databases


Discuss java.sql.Date value truncated using JDBC in MS-SQL Server in the comp.databases forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
ddog
 
Posts: n/a

Default java.sql.Date value truncated using JDBC in MS-SQL Server - 02-08-2007 , 04:34 PM






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() in a straight SQL Insert statement.

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!


Reply With Quote
  #2  
Old   
Lew
 
Posts: n/a

Default Re: java.sql.Date value truncated using JDBC in MS-SQL Server - 02-08-2007 , 07:21 PM






ddog wrote:
Quote:
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
You multi-posted this one to comp.lang.java.programmer as "Re: java.sql.Date
truncated when written to DB. How to obtain full date?".

Follow-up set to cljp. Please cease multi-posting. Use cross-posting if you
really want multiple groups.

- Lew


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.