2011-09-27 142 views
2

這是錯誤代碼:android.database.sqlite.SQLiteConstraintException:錯誤代碼19:約束失敗

09-27 11:56:01.425: WARN/System.err(10324): android.database.sqlite.SQLiteConstraintException: error code 19: constraint failed 
09-27 11:56:01.435: WARN/System.err(10324):  at android.database.sqlite.SQLiteStatement.native_execute(Native Method) 
09-27 11:56:01.435: WARN/System.err(10324):  at android.database.sqlite.SQLiteStatement.execute(SQLiteStatement.java:61) 
09-27 11:56:01.435: WARN/System.err(10324):  at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1809) 
09-27 11:56:01.435: WARN/System.err(10324):  at de.enough.appmate.dbase.CMSResource.updateItem(CMSResource.java:1103) 
09-27 11:56:01.435: WARN/System.err(10324):  at de.enough.appmate.dbase.CMSResourceUpdater.updateItems(CMSResourceUpdater.java:178) 
09-27 11:56:01.435: WARN/System.err(10324):  at de.enough.appmate.dbase.CMSResourceUpdater.loadUpdates(CMSResourceUpdater.java:102) 
09-27 11:56:01.435: WARN/System.err(10324):  at de.enough.appmate.dbase.CMSResourceUpdaterRunnable.run(CMSResourceUpdaterRunnable.java:32) 
09-27 11:56:01.435: WARN/System.err(10324):  at java.lang.Thread.run(Thread.java:1019) 

,這是用於

this.db.execSQL("INSERT INTO itemGalleryItems (id, imageCaption, imageUrl,itemID,orderIndex,displayInGallery) VALUES (?,?,?,?,?,?); ", 
         bindArgs); 

的binArgs貌似方法:

String[] bindArgs = { 
     (String) imageItem.get("id"), 
     (String) imageItem.get("imageCaption"), 
     (String) imageItem.get("imageName"), 
     (String) item.get("id"), 
     (String) imageItem.get("orderIndex"), 
     (String) imageItem.get("displayInGallery")}; 

希望有人能幫助

thanx newone

+0

定義不完全填充當您插入該值檢查約束的約束。請在這裏顯示你的表格結構,這樣我們可以看到什麼約束失敗 – Pratik

+0

我有同樣的問題,但對我來說,[這] [1]工作。 [1]:http://stackoverflow.com/questions/8117685/android-database-sqlite-sqliteconstraintexception-error-code-19-constraint-fai – GreenBee

回答

4

我想如果你有autoincrement字段,你不應該在查詢中包含它...是「id」autoincrement?

+0

我不知道,但我覺得這是沒有自動增量.... – newone

+0

好吧,試試吧,只是從參數和查詢 – mihail

+0

刪除ID多數民衆贊成多好....錯誤不會回來......但現在我有一個新的。 ... – newone

3

看看你的插入語句。它是否具有在表create語句中聲明爲非空的所有列? 並嘗試使用「id」列,而不是使用「_id」。

+0

當我改變ID爲_id比我得到這個失敗:android.database.sqlite.SQLiteException:表itemGalleryItems沒有名爲_id的列:,編譯時:INSERT INTO itemGalleryItems(_id,imageCaption,imageUrl,itemID,orderIndex,displayInGallery)VALUES(?,?,?,?,?,?); – newone

+0

將id更改爲_id是一個建議。如果您在表的create語句中提供了一個id列名稱,那麼您必須在所有其他語句中使用id。 – nixan

+0

看看這裏:[link](http://stackoverflow.com/questions/7568062/stupid-error-android-database-sqlite-sqliteconstraintexception-error-code-19-co) – newone

8

我修復了這個錯誤;

代替

long sucess = db.insert(TABLE_NAME_CONTACT_EXTRA, null, row); 

使用這種在數據庫中插入數據

long sucess = db.insertWithOnConflict(TABLE_NAME_CONTACT_EXTRA, null, 
       row, SQLiteDatabase.CONFLICT_IGNORE); 
某人領域
相關問題