Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

java.sql.date trims the time?

843854Jun 11 2003 — edited Jul 16 2003
Hi all,
Here's my setup:
MS SQL 2000 server
2 DateTime fields in table SystemInfo (you can only have 1 Timestamp, so I need to use DateTime)

My problem is that I need to recored both the date and time in the DateTime field, but java.sql.date ignores the hours/minutes/seconds part. I've done some debugging, and the trim occurs before the execute call. Is there a good way to preserve the whole Date value when going to java.sql.date? Here's my code:
        System.out.println("Update System Info");
        sql.clearBatch();
        sql = conn.prepareStatement("update SystemInfo set Created=?, Modified=? where Parent = ?");
        sql.setDate(1, new java.sql.Date(sys.getCreated().getTime()));
        System.out.println(new java.sql.Date(sys.getCreated().getTime()));
        sql.setDate(2, new java.sql.Date(sys.getLastModified().getTime()));
        sql.setString(3, parent.toString());
        
        //sql.executeUpdate();
So after I create a new java.util.Date, print it, package it into my sys object (sys.getCreated() returns a java.util.Date),
send it to the block above, here's the output:


Wed Jun 11 16:55:25 EDT 2003
Update System Info
2003-06-11

What's the right way to do this? Thanks !

Jim
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 13 2003
Added on Jun 11 2003
3 comments
389 views