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:Mark Matthews (ma@mysql.com)
Date:01/05/2006 01:22:20 PM
List:com.mysql.lists.java

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

Robert DiFalco wrote:

The comments don't make sense? It seems straightforward. I assumed this was a well known enough issue to not have to write out a full example, here's some pseudo-code:

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

INSERT INTO TimestampTable(stamp) VALUES (?)

ps.setTimestamp( stamp ); ps.executeUpdate();

// Now try to query a record with that timestamp: SELECT COUNT(*) FROM TimestampTable WHERE stamp = ?

ps.setTimestamp( stamp ); rset = ps.executeQuery(). rset.next(); assert rset.getInt( 1 ) == 1;

Robert, what does the table itself look like? It's not a "well known problem", since it seems to work for most folks. For example, the output of this is "1":

Connection c = d.connect("jdbc:mysql://localhost:3308/test?user=root", null); c.createStatement().executeUpdate("DROP TABLE IF EXISTS foo_ts"); c.createStatement().executeUpdate("CREATE TABLE foo_ts(field1 int, ts_field TIMESTAMP)"); PreparedStatement pstmt = c.prepareStatement("INSERT INTO foo_ts VALUES (1, ?)"); Timestamp t = new Timestamp(System.currentTimeMillis()); pstmt.setTimestamp(1, t); pstmt.executeUpdate();

pstmt = c.prepareStatement("SELECT COUNT(*) FROM foo_ts WHERE ts_field=?"); pstmt.setTimestamp(1, t); ResultSet rs = pstmt.executeQuery(); rs.next(); System.out.println(rs.getString(1));

-Mark - -- MySQL Java Mailing List For list archives: http://lists.mysql.com/java To unsubscribe: http://lists.mysql.com/java?unsub=rdif@tripwire.com

iD8DBQFDvY4itvXNTca6JD8RAgcdAJ93mS9X9DMSaX9prVYIIn/gj93yPACdF2KD i1JdMbSy/Q6SH9bHUTVZZbM= =e9XG -----END PGP SIGNATURE-----