.SQLiteException:near“,”:语法错误(代码1):,编译时:

时间:2014-03-24 15:43:32

标签: android database sqlite syntax-error

我错过了什么?用","但我似乎在寻找错误的地方。这是我的代码:

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));

3 个答案:

答案 0 :(得分:8)

重命名或引用自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 +"));";

答案 1 :(得分:-1)

您需要为要为表定义的列添加数据类型。您已为KEY_ROWID添加了整数dataType,但忘记为其余的添加dataTypes。

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

答案 2 :(得分:-1)

尝试在create table命令中删除“IF NOT EXIST”,Android版4.0.4中的SQLite给我这个错误,而不是4.4.2

运气。