Java – transactions in the database do not work in Android

I used the following code, but encountered some problems:

mDb.beginTransaction();
String updateQuery ="Query entered here"; 
String[] valVars = { Variables initialized here };
Cursor c = mDb.rawQuery(updateQuery,valVars);
if (c != null)
{
    mDb.setTransactionSuccessful();
    mDb.endTransaction();
    return true;
}
else
{ 
    mDb.endTransaction();
    return false;
}

When I use debug instead of running return true, it will directly return false, even if it is in an else statement Please tell me what the problem is and how to do it correctly

Solution

Use this construct, as described in the documentation:

db.beginTransaction();
try {
    ...
    db.setTransactionSuccessful();
} finally {
    db.endTransaction();
}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>