6

I am developing an application which requires use of an SQLite database. I have implemented fetching the data, but I am facing problems when I try to insert data. The problem that I am having is that the new data I enter is not stored, i.e nothing is new is being entered into the database.

This is my insert code, myDataBase is an instance of SQLiteDatabase.

public void insertTitle(String Recipe)  
{  
    ContentValues initialValues = new ContentValues();  
    initialValues.put(COLUMN_NAME,value);  
    myDataBase.insert(ZRECIPE, null, initialValues);  
 }
Ross
  • 46,186
  • 39
  • 120
  • 173
Jaymin
  • 61
  • 1
  • 2

3 Answers3

5

Try it this way. You need first start transaction, then mark it as successful and end.

   try {  
       myDataBase.beginTransaction();
       myDataBase.insert(ZRECIPE, null, initialValues);
       myDataBase.setTransactionSuccessful();
       } 
   finally {
       myDataBase.endTransaction();
       }
Konstantin Burov
  • 68,980
  • 16
  • 115
  • 93
  • Is it necessary to do an explicit transaction in order to get it to commit? Doesn't SQLite use autocommit mode by default? – LarsH Nov 13 '17 at 18:42
2

You forgot to commit the transaction.

habnabit
  • 9,906
  • 3
  • 32
  • 26
0

Try with this code this may help you

public void insertTitle(String Recipe)  
{  
    ContentValues initialValues = new ContentValues();  
    initialValues.put(COLUMN_NAME,Recipe);  
    myDataBase.insert(ZRECIPE, null, initialValues);  
 }
Nagaraja
  • 581
  • 1
  • 4
  • 12