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

时间:2016-11-07 08:06:46

标签: java sqlite

我不确定为什么会收到此错误。

@Override
public void onCreate(SQLiteDatabase db){

    String SQL_CREATE_GOAL_TABLE = "CREATE TABLE"+ GoalContract.GoalEntry.TABLE_NAME + " ("
            + GoalContract.GoalEntry._ID + "INTEGER PRIMARY KEY,"
            + GoalContract.GoalEntry.COLUMN_GOAL_NAME + "TEXT);";
    db.execSQL(SQL_CREATE_GOAL_TABLE);

}

1 个答案:

答案 0 :(得分:2)

你错过了很多空格:

String SQL_CREATE_GOAL_TABLE = "CREATE TABLE "+ GoalContract.GoalEntry.TABLE_NAME + " ("
            + GoalContract.GoalEntry._ID + " INTEGER PRIMARY KEY,"
            + GoalContract.GoalEntry.COLUMN_GOAL_NAME + " TEXT);";

请注意'table '之后' Integer'' TEXT'之后的其他空格。

如果生成的SQL中存在语法错误,则调试和查看生成的String非常有用。