2013-07-02 83 views
0

我有一个预制数据库的应用程序。我想改变这个数据库中的条目并保存它,但是我遇到了一些麻烦。我有内部的以下方法DatabaseHelper:数据库更新但不保存

public void updateStats(int rowId, int correct, int attempts) { 
     //Method for updating the stats after a question is answered 

     SQLiteDatabase db = this.getWritableDatabase(); 

     ContentValues args = new ContentValues(); 
     args.put("CORRECT", correct); 
     args.put("ATTEMPTS", attempts); 
     db.update("CHARACTERS", args, "_id=" + rowId, null); 

     Cursor c = db.query("CHARACTERS", null, null, null, null, null, null); 
     c.moveToPosition(rowId-1); 
     Log.d("database", "test - " + String.valueOf(c.getInt(0))); 

     db.close(); 

    } 

这似乎是运行更新罚款,这是因为查询显示,该变化已在日志中完成的。但是当我结束活动时,应用程序正在恢复到原始数据库。

我在Android中使用数据库的知识是不完整的,所以我可能错过了一些简单的东西。有谁知道发生了什么问题?

+0

看到http://www.androidhive.info/2011/11/android-sqlite-database-tutorial/。这可以帮助你。 –

+0

你可以发布你的数据库路径吗? – Nas

+0

@Deen Sure:“/data/data/"+context.getPackageName()+"/"+"databases/”; –

回答

0

,请尝试使用此

ContentValues dataToInsert = new ContentValues(); 
          dataToInsert.put(ALBUM_IS_COMPLETE, "true"); 
          String where = "album_id=?"; 
          String[] whereArgs = {albumid}; 
          try 
           { 
            openDataBase(); 
            myDataBase.update(DATABASE_ALBUM_TABLE, dataToInsert, where, whereArgs); 
           } 
          catch (Exception e) 
           { 
           } 

希望这将帮助你

+0

我很困惑,是不是基本上与我发布的代码相同的技术? –

+0

你试过这个吗 – farrukh

+0

你是从唯一的一个位置更新你的数据库吗? – farrukh

相关问题