Android SQLiteOpenHelper:错误代码= 1,msg =接近“create”:语法错误

时间:2013-01-19 16:02:41

标签: android database sqliteopenhelper

这是我创建数据库表的代码:

public void onCreate(SQLiteDatabase db) {
        Log.i(TAG, "Inizio creazione database MessagesDB");
        String CREATE_TABLE = "CREATE TABLE " + TABLE2 + " (" + Key_key + " TEXT PRIMARY KEY, " + Key_ID + " INTEGER NOT NULL, " + Key_author + " TEXT NOT NULL, " 
+ Key_date_create + " TEXT NOT NULL, " + Key_sender + " TEXT, " 
+ Key_date_sent + " TEXT, " + Key_recipient + " TEXT, " 
+ Key_date_received + " TEXT, " + Key_message + " TEXT, " 
+ Key_message_path + " TEXT, " + Key_size + " INTEGER" + ");";  
        try {
            db.execSQL(CREATE_TABLE); 
            Log.i(TAG, "Creazione database MessagesDB avvenuta con successo");
        }
        catch (Exception e){
            Log.e(TAG, "Errore nella create table messages", e);
        }   
}

但我在logcat中有错误:

:Errore nella create table messages
:android.database.sqlite.SQLiteException: near "create": syntax error: CREATE TABLE messagesDB (_key TEXT PRIMARY KEY, _id INTEGER NOT NULL, author TEXT NOT NULL, date create TEXT NOT NULL, sender TEXT, date_sent TEXT, recipient TEXT, date_received TEXT, message TEXT, message_path TEXT, size INTEGER);

我不明白为什么会出现这个错误。 有人能帮我理解吗? (抱歉我的英语不好)。

1 个答案:

答案 0 :(得分:3)

create移除date create TEXT NOT NULL。你似乎错误地添加了它。

看起来Key_date_create的值为date create,也许您的意思是date_create