This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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?