ContentValues ​​Method

On the db side checkInTimeand checkOutTimeare of typeTIMESTAMP

In my java-code well checkInTimeand checkOutTimeare of the typejava.sql.Timestamp

To insert an entry in db, I use 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 get compilation errors in lines 4 and 5, since they do not expect something like java.sql.Timestamp

I do not see any put method from C ontentValuesthat will accept a type java.sql.Timestampin the second parameter. Please suggest how to pass java.sql.Timestampin such a case so that I can also remove compilation errors.

Thank,

+3
source share
2 answers

I suggest you use DATETIMEinstead TIMESTAMP. It is more common when processing dates and times.

, SimpleDateFormat DATETIME .

final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

:

, :

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));
+7

checkInTime checkOutTime , , thm contentvalue, , . ContentValue timeStamps, , .

0

All Articles