Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android SQLite中的事务和准备好的语句_Android_Sqlite_Transactions_Android Sqlite_Prepared Statement - Fatal编程技术网

Android SQLite中的事务和准备好的语句

Android SQLite中的事务和准备好的语句,android,sqlite,transactions,android-sqlite,prepared-statement,Android,Sqlite,Transactions,Android Sqlite,Prepared Statement,我正在使用Android 5.1和SQLite数据库。我已准备好以下声明和交易: String stringValue = "hello"; try { String sql = "INSERT INTO table_name (column_1, column_2) VALUES (?, ?)"; SQLiteStatement statement = db.compileStatement(sql); db.beginTransaction(); for

我正在使用Android 5.1和SQLite数据库。我已准备好以下声明和交易:

String stringValue = "hello";
try {

    String sql = "INSERT INTO table_name (column_1, column_2) VALUES (?, ?)";
    SQLiteStatement statement = db.compileStatement(sql);
    db.beginTransaction();

    for (int i = 0; i < 1000; i++) {
        statement.clearBindings();
        statement.bindLong(1, i);
        statement.bindString(2, stringValue + i);
        statement.executeInsert();
    }

    db.setTransactionSuccessful(); // This commits the transaction if there were no exceptions

} catch (Exception e) {
    Log.w("Exception:", e);
} finally {
    db.endTransaction();
}
String stringValue=“hello”;
试一试{
String sql=“插入表名称(列1,列2)值(?,)”;
SQLiteStatement=db.compileStatement(sql);
db.beginTransaction();
对于(int i=0;i<1000;i++){
语句。clearBindings();
声明.bindLong(1,i);
语句.bindString(2,stringValue+i);
语句。executeInsert();
}
db.setTransactionSuccessful();//如果没有异常,则提交事务
}捕获(例外e){
Log.w(“例外情况:”,e);
}最后{
db.endTransaction();
}
这是行不通的。不工作意味着
语句.executeInsert()块,即没有异常或错误,但它只是永远停止。当我首先启动事务,然后编译准备好的语句时,它会工作,即
语句.executeInsert()被执行,并且返回速度非常快


为什么这不起作用,而且不可能只编译一次准备好的声明,而不是每次交易。

请编辑您的问题,并详细解释“这不起作用”的含义和“它起作用”的含义。您也可以考虑只使用<代码>插入()/<代码>方法在<代码> SQLITDATABASE < /C>中,而不是<代码> SQLITestAtest。