0

我正在数据库 order.db 中创建一个名为 order 的表。在执行函数调用“database.execSQL(DATABASE_CREATE)”期间出现错误。

错误如下:

04-17 02:06:35.014: E/AndroidRuntime(4612): android.database.sqlite.SQLiteException: near "order": syntax error (code 1): , while compiling: create table order ( _id integer primary key autoincrement, orderName text not null, orderCommission text not null, orderDate text not null, orderSlot text not null, orderGain text not null, orderNO text not null, orderValue text not null);


package com.shoaib.lotteryerp.helper;

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

public class MySQLiteHelperOrder extends SQLiteOpenHelper {

    public static final String TABLE_ORDER = "Order";
    public static final String COLUMN_ID = "_id";
    public static final String COLUMN_NAME = "orderName";
    public static final String COLUMN_DATE="orderDate";
    public static final String COLUMN_ORDERNO="orderNO";
    public static final String COLUMN_SLOT="orderSlot";

    public static final String COLUMN_ORDERVALUE="orderValue";
    public static final String COLUMN_COMMISSION="orderCommission";
    public static final String COLUMN_GAIN="orderGain";
    private static final String DATABASE_NAME = "order.db";
    private static final int DATABASE_VERSION = 2;

    // Database creation sql statement
    private static final String DATABASE_CREATE = "create table "
            + TABLE_ORDER + "(" + COLUMN_ID
            + " integer primary key autoincrement, " + COLUMN_NAME
            + " text not null, " + COLUMN_COMMISSION + " text not null, "
            + COLUMN_DATE + " text not null, "
            + COLUMN_SLOT + " text not null, "
            + COLUMN_GAIN + " text not null, "
            + COLUMN_ORDERNO + " text not null, " + COLUMN_ORDERVALUE
            + " text not null);";

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

    public void onCreate(SQLiteDatabase database) {
        database.execSQL(DATABASE_CREATE);
    }

    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        Log.w(MySQLiteHelperOrder.class.getName(),
                "Upgrading database from version " + oldVersion + " to "
                        + newVersion + ", which will destroy all old data");
        db.execSQL("DROP TABLE IF EXISTS " + TABLE_ORDER);
        onCreate(db);
    }
}
4

1 回答 1

2

尝试将表的名称更改为其他名称。order是 sql 中的保留字(即order by)。

于 2013-04-17T11:28:26.270 回答