0

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.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Ishan hrx
  • 403
  • 8
  • 19
  • Does the same occur with using Android insert method - browser_data.insert(String tableName, String nullColumnHack, ContentValues values); ? – Sergey Emeliyanov Sep 19 '17 at 18:06
  • You need to provide a stack trace. – Christopher Schneider Sep 19 '17 at 18:24
  • I assume you are having format problem, cannot be sure without seeing logs. you can check following link for formats. https://stackoverflow.com/questions/1933720/how-do-i-insert-datetime-value-into-a-sqlite-database – Vurgun M Sep 19 '17 at 18:39

2 Answers2

1

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.

Chirag
  • 478
  • 4
  • 10
0

convert new Date() to string and try to insert . because date column attribute may be string or text

Ajithkumar M
  • 41
  • 10