aspose file tools*
The moose likes JDBC and the fly likes save Date() into mysql Timestamp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "save Date() into mysql Timestamp" Watch "save Date() into mysql Timestamp" New topic
Author

save Date() into mysql Timestamp

Mike Southgate
Ranch Hand

Joined: Jul 18, 2003
Posts: 183
I have an object with a Date() member. I need to insert this in a MySql database column of type timestamp.

my code is as folllows:

String insrtSQL = "INSERT INTO run VALUES (?,?,?,?,?,NOW(),?,?)";
PreparedStatement ps = cnctn.prepareStatement(insrtSQL);
ps.setString(1, this.userId);
ps.setInt(2, maxRunId);
ps.setTimestamp(3, new Timestamp(((Lap)this.laps.get(1)).getTs().getTime()));
ps.setNull(4, Types.NULL);
ps.setNull(5, Types.NULL);
ps.setString(6, this.comment);
ps.setNull(7, Types.NULL);
ps.execute();

laps is an arraylist containing Lap objects Lap.getTs() returns a java.util.Date. As you can see, I convert java.util.Date into a java.sql.Timestamp. println shows the timestamp as populated correctly but in the database it is just zeros. Any suggestions?

ms


ms<br />SCJP, SCJD
 
Don't get me started about those stupid light bulbs.
 
subject: save Date() into mysql Timestamp