lundi 7 mars 2016

Android: Update SQLite database

I am new to Android. I am trying to update information in sqlite database. Most of the time I able to update the information but sometimes my phone come out with error of updating. I had debugged many times, it shows nothing wrong with my code. I am using Android Version 5.1.1 Lollipop as testing tool. Most of the times, updating sqlite is working fine but sometimes the application will crash.

The following is my code update code. Please tell me what's wrong with my code.

public void updateArticle(String NewName, String oldName) {
    SQLiteDatabase db = getWritableDatabase();
    ContentValues values = new ContentValues();
    values.put(COLUMN_ARTICLENAME, NewName);
    db.update(TABLE_ARTICLE, values, COLUMN_ARTICLENAME + " = '" + oldName + "'", null);
    db.close();
}

Thank you.

Aucun commentaire:

Enregistrer un commentaire