0

当我尝试插入我的 SQLite 数据库时,没有抛出错误消息。我的问题是,里面好像什么都没有写,rowid总是保持1。当我从这个表中选择出来时,它的大小cursor是0。

我确定ename, ezeit,egenaueres有值。

这是我的插入功能:

public void insertereignis(String ename, String ezeit, String egenaueres){
    long rowId = -1;
    try{    
        SQLiteDatabase db = getWritableDatabase();
        db.beginTransaction();

        ContentValues cv = new ContentValues();
        System.out.println(ename + ezeit + egenaueres);
        cv.put(EREIGNISNAME, ename);
        cv.put(EREIGNISZEIT, ezeit);
        cv.put(EREIGNISGENAUERES, egenaueres);

        rowId = db.insert(TABLE_NAME_EREIGNIS, null, cv);
        db.endTransaction();

        selectEreignis();

    }
    catch (SQLiteException e){
        Log.e(TAG, "insert() Ereignis", e);
    }
    finally{
        Log.d(TAG, "insert(): Ereignis rowId=" + rowId);
    }

这是我的选择函数,光标大小为 0:

public Cursor selectEreignis(){
        SQLiteDatabase db = getReadableDatabase();
        db.beginTransaction();
        Cursor cursor = db.query(TABLE_NAME_EREIGNIS, new String[] {"ereignisname", "ereigniszeit", "ereignisgenaueres"}, 
                null, null, null, null, null);
        db.endTransaction();
        System.out.println("HALLLIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII"  + cursor.getCount());
        return cursor;
    }

该表如下所示:

private static final String TABLE_EREIGNIS_CREATE = "CREATE TABLE IF NOT EXISTS " + TABLE_NAME_EREIGNIS + " (" + ereignisid + " INTEGER PRIMARY KEY AUTOINCREMENT, "
        + EREIGNISNAME + " TEXT, " + EREIGNISZEIT + " TEXT, " + EREIGNISGENAUERES + " TEXT, " + KINDID + " INTEGER, FOREIGN KEY (" + KINDID + ") REFERENCES " + TABLE_NAME_Kind + "(" + id + "));";

我的问题是什么?

4

1 回答 1

2

好的,我发现了问题。使用 db.beginTransaction();anddb.endTransaction();是我的问题。删除了这一行,一切正常。

于 2013-05-07T09:45:23.977 回答