473,233 Members | 1,538 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,233 software developers and data experts.

Full date value not being written via JDBC - any ideas?

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!

Feb 8 '07 #1
2 5729
MackTheKnife (wg********@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, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Feb 8 '07 #2
On Feb 8, 2:32 pm, "MackTheKnife" <wgblack...@yahoo.comwrote:
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

Feb 9 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: billb | last post by:
I am writing a datetime field value to MS SQL Server 7 in the following manner via a stored procedure: // item to be written is originally a java.util.Date object java.util.Date fromDate; //...
1
by: balleyman47 | last post by:
getting the following error when executing an insert statement: java.lang.IllegalArgumentException: Date/Time must be JDBC format running on UDB 8.2 fix pack 10 using IBM type IV driver. Query...
1
by: sbanil | last post by:
We have a JAVA application which uses following Database product name : DB2 Database product version : DSN07012 JDBC driver name : IBM DB2 JDBC Universal Driver Architecture JDBC driver version ...
12
by: Assimalyst | last post by:
Hi, I have a working script that converts a dd/mm/yyyy text box date entry to yyyy/mm/dd and compares it to the current date, giving an error through an asp.net custom validator, it is as...
9
by: Kenevel | last post by:
Hi everyone, Has anyone come across a problem where on Linux using DB2 9.1 Express- C with the packaged jcc-JDBC driver that it fails correctly to parse a returned date value? I'm simply calling...
1
by: cjordan | last post by:
Hi everyone. I'm new here, and I think I've got a pretty unique problem (haven't found any solution to this anywhere else), but I'm hoping that someone here can help me. To be honest, I'm not a...
3
by: esu | last post by:
I got the above error on the following code: Please help me. public void setCheckinDate(int reservationNumber) throws SQLException, ClassNotFoundException, InstantiationException,...
19
by: robtyketto | last post by:
Greetings, I have the following code below which allows the date to be added via a JDBC connection as a STRING. The value of dateString is inserted into the MS ACCESS database. What is the...
9
by: TC | last post by:
Hi. I have some ASP written in VB.net which is currently installed on a customers server. The asp connects to a local MySql database and retrieves data for the customers customers. If you see...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.