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);
}
}
謝謝。它幫助! –