Reputation: 423
I am trying to make an android browser, using SQLite databse to store history, bookmarks etc. It works fine when I insert Bookmarks but the app crashes when history is being entered. Also everything is working fine in android 7.0.
This is how I am trying to insert history in my database.
browser_data.execSQL("Insert into tb_history values('"+DateFormat.getDateTimeInstance().format(new Date())+"', '"+SqlCompatible(view.getTitle())+"' , '"+SqlCompatible(ac_sub)+"', '"+SqlCompatible(view.getUrl())+"');");
public static String SqlCompatible(String str){
str = str.replaceAll("'", "''");
return str;
}
Bookmarks and history table have just one difference which is the extra time and date column in history table.
Also I am pretty sure that table is being created correctly as I checked that, and also it's working in android 7.0, I also checked logcat but found nothing suspicious. I can post it if you guys want it.
Upvotes: 0
Views: 100
Reputation: 478
If you are using these import files for date
import android.icu.text.DateFormat;
import java.text.SimpleDateFormat;
then try replacing them with
import java.text.DateFormat;
At least it solved the issue for me. Hope it works for you too.
Upvotes: 1
Reputation: 39
convert new Date() to string and try to insert . because date column attribute may be string or text
Upvotes: 0