10 messages in com.mysql.lists.javaRE: setTimestamp/getTimestamp is Broken
FromSent OnAttachments
Robert DiFalco05 Jan 2006 11:29 
Mark Matthews05 Jan 2006 12:18 
Robert DiFalco05 Jan 2006 12:30 
Mark Matthews05 Jan 2006 12:34 
Robert DiFalco05 Jan 2006 12:57 
Mark Matthews05 Jan 2006 13:22 
Robert DiFalco05 Jan 2006 13:26 
Mark Matthews05 Jan 2006 13:31 
Robert DiFalco05 Jan 2006 14:09 
Eric Herman20 Jan 2006 08:28 
Subject:RE: setTimestamp/getTimestamp is Broken
From:Robert DiFalco (rdif@tripwire.com)
Date:01/05/2006 12:30:58 PM
List:com.mysql.lists.java

I'm using PreparedStatements, so that is not an issue. The issue is that I can't query for Timestamp equality as shown below.

-----Original Message----- From: Mark Matthews [mailto:ma@mysql.com] Sent: Thursday, January 05, 2006 12:19 PM To: Robert DiFalco Cc: ja@lists.mysql.com Subject: Re: setTimestamp/getTimestamp is Broken

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1

Robert DiFalco wrote:

Apparently, the TIMESTAMP column type in MySQL does not record milliseconds. Therefore it is not all the compatible with the java.sql.Timestamp class. For instance:

Timestamp stamp = new Timestamp( System.currentTimeMillis() );

// write record with this....

// search record for field with value = stamp

// no results! :(

Does anyone have a general pattern for dealing with this? Across database implementations? I suppose the easiest thing is to never use timestamp directly and create methods called #getTime and #getTimestamp something like this?

Robert,

You need to zero-out the nanos if you're not using prepared statements by calling Timestamp.setNanos(int). Are you using prepared statments (where this is taken care of for you), or are you generating plain statements on the fly?

-Mark - -- Mark Matthews MySQL AB, Software Development Manager - Connectivity www.mysql.com -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (MingW32) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFDvX8xtvXNTca6JD8RAuo2AJ9T6tuUqYA7/VxCYbe+gwmHwfVhLQCfa1tu uz02gyCvpHTBuRn0+qNFGgk= =fvhx -----END PGP SIGNATURE-----