2017-10-05 68 views
1

我的代碼在sqlite中總是得到一個語法異常。 它始終在DatabaseHelper的onCreate中突出顯示。 而錯誤可能在創建表「訂單」。android.database.sqlite.SQLiteException:在「Order」附近:語法錯誤(代碼1):

我正在使用Android Studio並通過在listview中通過適配器填充類來開發訂購系統。

這是我的代碼:

package com.example.lenovot420.yumburgers; 

import android.content.Context; 
import android.database.sqlite.SQLiteDatabase; 
import android.database.sqlite.SQLiteOpenHelper; 

/** 
* Created by lenovot420 on 9/24/2017. 
*/ 

public class DatabaseHelper extends SQLiteOpenHelper { 

//version number to upgrade database version 
//each time if you Add, Edit table, you need to change the 
//version number. 
private static final int DATABASE_VERSION = 1; 

// Database Name 
private static final String DATABASE_NAME = "JollibeeOrder.db"; 

public DatabaseHelper(Context context) { 
    super(context, DATABASE_NAME, null, DATABASE_VERSION); 
} 

@Override 
public void onCreate(SQLiteDatabase db) { 
    //All necessary tables you like to create will create here 

    String CREATE_TABLE_ORDER = "CREATE TABLE " + Order.TABLE + " (" 
      + Order.KEY_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " 
      + Order.KEY_ORDER_NAME + " TEXT, " 
      + Order.KEY_ORDER_EXTRA + " TEXT, " 
      + Order.KEY_ORDER_PRICE + " TEXT, " 
      + Order.KEY_ORDER_QUANTITY + " TEXT, " 
      + Order.KEY_ORDER_TOTAL + " TEXT, " 
      + Order.KEY_ORDER_PHOTO + " INTEGER)"; 

    db.execSQL(CREATE_TABLE_ORDER); 

} 


@Override 
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { 

    // Drop older table if existed, all data will be gone!!! 
    db.execSQL("DROP TABLE IF EXISTS " + Order.TABLE); 

    // Create tables again 
    onCreate(db); 

} 
} 

回答

1

ORDERsqlite keyword,不能用作標識符。您或者需要"quote it"甚至更​​好,請將其重命名爲不是關鍵字的內容。

+0

謝謝。它幫助! –

相關問題