Android.database.sqlite.SQLiteException

时间:2013-04-17 11:26:01

标签: android sqlite

我正在数据库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);
    }
}

1 个答案:

答案 0 :(得分:2)

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