簡體   English   中英

Android.database.sqlite.SQLiteException

[英]Android.database.sqlite.SQLiteException

我正在數據庫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);
    }
}

嘗試將表名更改為其他名稱。 order是sql中的保留字(即order by )。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM