0

*TABLE NOT UPDATING*****HOW TO SOLVE THE PROBLEM

public String getElapsedTime(String session_id, String time) {
    db = this.getWritableDatabase();
    db.beginTransaction();
    db.setTransactionSuccessful();
    Log.d("CHINMAY", "Update in Sql get ElapsedTime " + session_id + "\n" + time);
    ContentValues cv = new ContentValues();
    cv.put(ELAPSED_TIME, time);
    db.update(TABLE_SESSION_TEST, cv, "session_id=?", new String[]{session_id});
    db.endTransaction();
    return "Checking Update";
}

1 Answer 1

2

You need to mark your transaction as "clean" by calling db.setTransactionSuccessful() before calling db.endTransaction(). If you do not set your transaction as successful, your changes are immediately rolled back as soon as the transaction is ended (as it assumes there was an error).

For more information, see the SQLiteDatabase documentation here

Sign up to request clarification or add additional context in comments.

6 Comments

I didn't understand how to clean.
db.update(TABLE_SESSION_TEST, cv, "session_id=?", new String[]{session_id}); db.setTransactionSuccessful(); db.endTransaction();
db.update() returns an integer of how many rows have been updated. When that code runs, does db.update() return a 0 or a 1? If it's a 0, check your data and query to make sure it's correct.
i changed the code and return boolean value output is coming toast.message as true.But database i checked is not displaying.
Actually i tried the code is updated after some time. But when i move to next activity the value is not coming immediately
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.