Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Data not inserting in Sqlite database in android

Tags:

android

sqlite

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);  
 }
like image 701
Jaymin Avatar asked Aug 14 '10 11:08

Jaymin


2 Answers

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();
       }
like image 181
Konstantin Burov Avatar answered Sep 29 '22 10:09

Konstantin Burov


You forgot to commit the transaction.

like image 26
habnabit Avatar answered Sep 29 '22 11:09

habnabit