At the db side, checkInTime and checkOutTime are of type TIMESTAMP
In my java code also, checkInTime and checkOutTime are of type java.sql.Timestamp
For inserting a record into db, i am using this piece of code:
1. ContentValues contentValues=new ContentValues();
2. contentValues.put(USER_ID, userId);
3. contentValues.put(ROOM_ID, roomId);
4. contentValues.put(CHECK_IN, checkInTime);
5. contentValues.put(CHECK_OUT, checkOutTime);
6. return database.insert(MRM_BOOKING_DETAILS_TABLE, null, contentValues);
But i am getting compilation errors at line 4 and 5 since they are not expecting something of type java.sql.Timestamp
I can't see any put method of ContentValues which will accept type java.sql.Timestamp in its second parameter. Please suggest how to pass the java.sql.Timestamp in such a case so that i can remove the compilation errors as well.
Thanks,
I would suggest you to use DATETIME instead of TIMESTAMP. Its more general when handling dates and times.
Moreover, you can use SimpleDateFormat to parse DATETIME values when inserting or reading from database.
final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Updated:
Try doing it as below:
final SimpleDateFormat parser = new SimpleDateFormat("yyyy-MM-ddTHH:mm:ss.SSS");
contentValues.put(CHECK_IN, parser.format(checkInTime));
contentValues.put(CHECK_OUT, parser.format(checkOutTime));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With