Android SQLITEDatabase this.getWritableDatabase()无法正常工作

时间:2018-12-06 00:06:45

标签: android database

我有以下代码,由于某些原因,this.getWritableDatabase()无法正常工作。它创建了数据库,但是我无法向其中添加数据。

public class DatabaseHelper extends SQLiteOpenHelper {

public static final String DATABASE_NAME = "daysDATABASEokt.db";
public static final String TABLE_NAME = "daysDATABASE";
private static final String COL1 = "datez";
private static final String COL2 = "json";

public DatabaseHelper(Context context) {
    super(context, DATABASE_NAME, null, 1);
}

@Override
public void onCreate(SQLiteDatabase db) {
    db.execSQL("CREATE TABLE " + TABLE_NAME + " (id INTEGER PRIMARY KEY AUTOINCREMENT, datez TEXT, json TEXT)");

}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
    onCreate(db);
}

public boolean addData(String date, String json) {
    Log.e("BEFORE", "BEFORE GETWRITABLEDATABASE");
    SQLiteDatabase db = this.getWritableDatabase();
    Log.e("BEFORE2", "AFTER GETWRITABLEDATABASE");


    ContentValues contentValues = new ContentValues();
    contentValues.put("datez", date);
    contentValues.put("json", json);
    db.insert(TABLE_NAME, null, contentValues);
    return true;
}

我在LogCat中收到此消息:

  

2018-12-06 00:03:15.141 5165-8081 / com.example.XZ.XC   E /之前:GETWRITABLEDATABASE之前

     

2018-12-06 00:03:15.273 5165-8081 / com.example.XZ.XC   E /之前:GETWRITABLEDATABASE之前

     

2018-12-06 00:03:15.448 5165-8081 / com.example.XZ.XC   E /之前:GETWRITABLEDATABASE之前

紧迫时间,因为我尝试向其中添加3个数据...同样应该有3个BEFORE2 ...

0 个答案:

没有答案