2014-03-24 39 views
3

我在想什麼?用「,」的東西,但我似乎看錯了地方。這是我的代碼:.SQLiteException:near「,」:語法錯誤(代碼1):,編譯時:

private static final String DATABASE_CREATE = 
     "CREATE TABLE if not exists " + SQLITE_TABLE + " (" + 
       KEY_ROWID + " integer PRIMARY KEY autoincrement," + 
       KEY_CURSUS + "," + 
       KEY_ONDERDEEL + "," + 
       KEY_GAME + "," + 
       KEY_TIJD + "," + 
       KEY_WEB + "," + 
       KEY_CHECK + "," + 
       " UNIQUE (" + KEY_ROWID +"));"; 

這是我的錯誤:

Caused by: android.database.sqlite.SQLiteException: near ",": syntax error (code 1): , while compiling: CREATE TABLE if not exists Games_getset (_id integer PRIMARY KEY autoincrement,cursus,onderdeel,game,tijd,web,check, UNIQUE (_id)); 
+0

在這裏看:http://stackoverflow.com/questions/18718178/android-sqlite-database-column-defined-in-create-table-script-but-not-creating-o/18718292#18718292 –

+0

列需要鍵入... – njzk2

回答

7

重命名或自check is a keyword in SQL引用check列。

例如:

private static final String DATABASE_CREATE = 
    "CREATE TABLE if not exists " + SQLITE_TABLE + " (" + 
      KEY_ROWID + " integer PRIMARY KEY autoincrement," + 
      KEY_CURSUS + "," + 
      KEY_ONDERDEEL + "," + 
      KEY_GAME + "," + 
      KEY_TIJD + "," + 
      KEY_WEB + "," + 
      + "`" + KEY_CHECK + "`," + 
      " UNIQUE (" + KEY_ROWID +"));"; 
+0

是的,我同意你 – CRUSADER

+0

謝謝laalto(和CRUSADER)! – user2378812

+1

我通過將列命名爲'cast'而犯了同樣的錯誤。在閱讀你的答案後,我意識到了錯誤。謝謝 –

-1

您需要添加數據類型要定義你的表中的列。您已經添加了整數數據類型KEY_ROWID卻忘了添加數據類型爲休息..

.........KEY_ROWID + " integer PRIMARY KEY autoincrement," + 
       KEY_CURSUS + " text," + 
       KEY_ONDERDEEL + " text," + ........ 
and so on... 
+0

這不是問題 - 只需指定名稱即可。問題是使用保留字「check」作爲混淆SQL解析器的列名稱。 – laalto

-1

嘗試刪除 「如果不存在」 在create table命令時,SQLite在Android版本4.0.4給我這個錯誤,而不是在4.4.2

運氣。

相關問題