How to get the Timestamp column value in android via cursor? How to get the Timestamp column value in android via cursor? sqlite sqlite

How to get the Timestamp column value in android via cursor?


You have to use the Cursor methods to get the value as a string and then use the Timestamp class's static valueOf method to convert it back to a proper Timestamp:

Timestamp.valueOf(cursor.getString(0))

I use this all over the place and it works like a charm. For example, while iterating over the result set, you can set the Timestamp fields of your object.

obj.setId(cursor.getLong(0));obj.setName(cursor.getName(1));obj.setAddDate(Timestamp.valueOf(cursor.getString(2)));

I hope that's what you're looking for.