0
我已經爲數據庫更新編寫了一個簡單的代碼,但它有時會更新,有時候不會......我已經寫了LOG進行構造,但日誌正在給出正確的輸出。這是我想要的:=數據庫值有時會更新,但有時不會?
public void updateDownloadedAssetNumberOfStartingBytesEncrypted(int id, int startingBytesEncrypted)
{
SQLiteDatabase database = null;
int numOfRowsUpdated = 0;
try
{
database = getWritableDatabase();
ContentValues values = new ContentValues();
values.put("StartingBytesEncrypted", startingBytesEncrypted);
if(database.isOpen())
{
Log.v("updating in db","doc id - "+id + " encrypted bytes - "+startingBytesEncrypted);
numOfRowsUpdated = database.update("_assets", values, "Id = "+id, null);
}
else
{
Log.v("Database","the database is not open thus starting encrypted bytes were not updated");
}
Log.v("muber of rows updated - ",""+numOfRowsUpdated);
}
catch(Exception ex)
{
}
finally
{
if(database != null)
{
database.close();
}
}
}
問題是什麼?任何幫助都是可以理解的。
您的代碼有點困惑。您可以將其簡化爲如下所示:\t \t ContentValues cv = new ContentValues(); \t \t cv.put(「name」,name); \t \t cv.put(「value」,value); \t \t getWritableDatabase()。insert(「cameras」,「name」,cv); \t \t close(); 在調用getWritableDatabase()後,無需檢查數據庫是否打開。 –