Android sqlite`db.execSQL()`强制关闭

时间:2016-03-30 11:54:42

标签: android sqlite

这是我onCreate方法中存在的db类的片段。在此方法之上定义了一个具有适当参数的构造函数。

因此,在运行它时,此方法的运行时日志表明它执行了 run1.2 ,但没有进一步执行。

public void onCreate(SQLiteDatabase db) {
        try{
          db = getWritableDatabase();
          db.beginTransaction();
          android.util.Log.w("check", "run1.1");
          String query = " CREATE TABLE check ( id INTEGER )";
          android.util.Log.w("check", "run1.2");
          db.execSQL(query, null);
          android.util.Log.w("check", "run1.3");
        }
        catch(Exception e){
            android.util.Log.w("check", e.toString());
        }

    }

1 个答案:

答案 0 :(得分:1)

删除execSQL来电的第二个参数。这是来自SQLiteDatabase.java的execSQL代码:

public void execSQL(String sql, Object[] bindArgs) throws SQLException {
    if (bindArgs == null) {
        throw new IllegalArgumentException("Empty bindArgs");
    }
    executeSql(sql, bindArgs);
}

仅限使用:

db.execSQL(query);