SQLite does not have its own type of storing date and time data. It can store a string or integer representation of a date instead.
To convert your values, you can use the date-time functions detailed in the documentation for the date and time functions Sqlite
Your initial attempt is almost correct, but the 'NOW'
argument is required to call the datetime () function.
String sql="INSERT INTO sms VALUES ( null, ?, ?, ?, datetime('NOW'))";
You should also call execSQL
instead of rawQuery
, which is waiting for the recordset to return.
dbw.execSQL(sql, new String[]{str1,str2,str3});
You can specify individual columns for inserting data by inserting a list of fields after the table name in your query, if you do not insert all values
String sql = "INSERT INTO sms(f1, f2, f3, f4)" + "VALUES ( null, ?, ?, ?, datetime('NOW'))";
Another option that may be possible is to use the default timestamp in SQLite , although I have not tried to do this in android.
source share