SQLite syntax error near “CREATE TABLE”

后端 未结 3 794
你的背包
你的背包 2021-01-23 06:40

Here\'s my code:

    String CREATE_DATABASE = \"CREATE TABLE \" + TABLE_NAME + \"(\"  + 
            KEY_ID + \" INTEGER PRIMARY KEY AUTOINCREMENT, \" + 
                


        
3条回答
  •  梦毁少年i
    2021-01-23 06:48

    Try this code in your onCreate method.

    1. Remove AUTOINCREMENT for KEY_ID as it is already declared as Primary KEY.
    2. Remove ";" you placed just after the last bracket in string i.e. second last semicolon in string CREATE_DATABASE.
    3. Remove db.close() from oncreate()

    Code To Replace: String CREATE_DATABASE = "CREATE TABLE "+TABLE_NAME+ " ( "+KEY_ID+" INTEGER PRIMARY KEY, "+KEY_TITLE+"TEXT, "+KEY_AUTHOR+"TEXT, "+KEY_STATE+"TEXT )"; db.execSQL(CREATE_DATABASE);

提交回复
热议问题