Cannot Insert Date and Time into MS Access database
843859Aug 8 2007 — edited Aug 9 2007I'm trying to insert the current date and time into my MS Access Database. I get no compile or run time errors and a record (row) gets created when the code is excecuted and all info is inserted correcly except the date & time. The last column (data and time) is left empty.
PreparedStatement pstmt = con.prepareStatement("INSERT INTO MyTable (a, b, c, Date)" + "VALUES(?,?,?,?)");
pstmt.setByte(1, a);
pstmt.setByte(2, b);
pstmt.setByte(3, c);
//For the last one, I use
pstmt.setTimestamp( 4, new java.sql.Timestamp( new java.util.Date().getTime()));
//or this:
//pstmt.setDate(4, new java.sql.Date(new java.util.Date().getTime()));
but neither works.
I googled this and read many of the threads here or in other forums. I found similar questions and accoording to them, what I have should work so I don't understand why it is not.
Would you please help. Thanks a lot in advance.