简体   繁体   中英

Data not inserting in Sqlite database in android

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, ie 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);  
 }

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();
       }

您忘记提交事务。

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);  
 }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM