2017-02-11 161 views
0

我在我的數據庫做了一些改變,從那以後,當我啓動它時,應用程序崩潰。我的代碼是:SQL數據庫「創建Tabe」

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幫助

+5

'TRANSACTION'是一個保留的關鍵字,在SQLite中:https://www.sqlite.org/lang_keywords.html –

回答

2

TRANSACTIONreserved keyword「,它不能用作表,索引,列,數據庫,用戶定義函數,歸類,虛擬表模塊或任何其他命名對象的名稱。你需要給你的表命名。

+0

好的,謝謝,第一次嘗試它的工作。我已經改變它,現在它工作。 – schisskiss