SQL数据库“创建Tabe”

时间:2017-02-11 18:38:40

标签: java android sqlite android-sqlite

我在我的数据库中进行了一些更改,从那时起,应用程序每次启动时都会崩溃。我的代码是:

public static final String TABLE_TRANSACTION = "transaction";
public static final String COLUMN_TRANSACTION_ID = "TRANSACTION_ID";
public static final String COLUMN_TRANSACTION_DATE_CREATED = "TRANSACTION_DATE_CREATED";
public static final String COLUMN_TRANSACTION_ISOVERVIEW = "TRANSACTION_ISOVERVIEW";
public static final String COLUMN_TRANSACTION_NAME = "TRANSACTION_NAME";
public static final String COLUMN_TRANSACTION_DESCRIPTION = "TRANSACTION_DESCRIPTION";
public static final String COLUMN_TRANSACTION_TYPE = "TRANSACTION_TYPE";
public static final String COLUMN_TRANSACTION_AMOUNT = "TRANSACTION_AMOUNT";
public static final String COLUMN_TRANSACTION_REPEAT_CYCLE = "TRANSACTION_REPEAT_CYCLE";
public static final String COLUMN_TRANSACTION_REPEAT_DAY = "TRANSACTION_REPEAT_DAY";
public static final String COLUMN_TRANSACTION_REPEAT_ACTIVE = "TRANSACTION_REPEAT_ACTIVE";

 private static final String DATABASE_CREATE_TRANSACTION = "create table "
        + TABLE_TRANSACTION + " ( "
        + COLUMN_TRANSACTION_ID + " integer primary key autoincrement, "
        + COLUMN_TRANSACTION_DATE_CREATED + " VARCHAR(16), "
        + COLUMN_TRANSACTION_ISOVERVIEW + " VARCHAR(10), "
        + COLUMN_TRANSACTION_NAME + " VARCHAR(4096), "
        + COLUMN_TRANSACTION_DESCRIPTION + " VARCHAR(4096), "
        + COLUMN_TRANSACTION_TYPE + " INTEGER, "
        + COLUMN_TRANSACTION_AMOUNT + " FLOAT, "
        + COLUMN_TRANSACTION_REPEAT_CYCLE + " VARCHAR(20), "
        + COLUMN_TRANSACTION_REPEAT_DAY + " VARCHAR(20), "
        + COLUMN_TRANSACTION_REPEAT_ACTIVE + " VARCHAR(10) );";

@Override
public void onCreate(SQLiteDatabase database) {
    database.execSQL(DATABASE_CREATE_TRANSACTION);
}

我得到了这个错误:

Caused by: android.database.sqlite.SQLiteException: near "transaction": syntax error (code 1): , while compiling: create table transaction ( TRANSACTION_ID integer primary key autoincrement, TRANSACTION_DATE_CREATED VARCHAR(16), TRANSACTION_ISOVERVIEW VARCHAR(10), TRANSACTION_NAME VARCHAR(4096), TRANSACTION_DESCRIPTION VARCHAR(4096), TRANSACTION_TYPE INTEGER, TRANSACTION_AMOUNT FLOAT, TRANSACTION_REPEAT_CYCLE VARCHAR(20), TRANSACTION_REPEAT_DAY VARCHAR(20), TRANSACTION_REPEAT_ACTIVE VARCHAR(10) );

你能说出错误在哪里吗? Thx for Help

1 个答案:

答案 0 :(得分:2)

TRANSACTIONreserved keyword,“它不能用作表,索引,列,数据库,用户定义函数,排序规则,虚拟表模块或任何其他命名对象的名称”。你需要为你的桌子命名别的东西。