java - 数据库中的事务在 android 中不起作用

标签 java android eclipse sqlite

我正在使用以下代码,但遇到了一些问题:

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;
}

当我使用 debug 而不是运行 return true 时,即使在 else 语句中,它也会直接返回 false。请告诉我问题是什么以及如何正确执行此操作。

最佳答案

使用此构造,如 documentation 中所述:

db.beginTransaction();
try {
    ...
    db.setTransactionSuccessful();
} finally {
    db.endTransaction();
}

关于java - 数据库中的事务在 android 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9157134/

相关文章:

java - GWT:更改树行的填充?

java - 读取 CSV 文件直到特定列号

java - 在(Eclipse 的)Jar 文件中设置类路径

java - 为什么我的条件从来没有满足过?

java - 错误: org. apache.hadoop.mapred.InvalidInputException:输入路径不存在

android - 如何删除滑动缓存 - android?

android - 如何跳过由 android CAMERA ACTIVITY 创建的 Activity ?

android - InputType 对自定义 EditText 没有影响

php - 识别 PHP 未使用的变量

当恰好有 404 个匹配项时,Eclipse 搜索结果丢失?