0
當我嘗試插入SQLite數據庫時,不會引發錯誤消息。我的問題是,它似乎沒有什麼是寫在這過,rowid始終保持1.當我這個表中選擇出來的cursor
的大小爲0插入錯誤:Rowid始終爲1
我敢肯定的是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 + "));";
什麼是我的問題?
+1嗯,你發現解決方案你自己:) – Lucifer 2013-05-07 10:05:37