我得到了一个例外,我无法弄清楚为什么会被抛出。当我添加表消息时出现异常。请看一看,看看是否有错过的错误。提前谢谢。
例外:
Caused by: android.database.sqlite.SQLiteException: near "From": syntax error (code 1): , while compiling: CREATE TABLE Messages (UniqueId TEXT PRIMARY KEY,From TEXT,To TEXT,Subject TEXT,Body TEXT,HandledOn TEXT,IsRead INTEGER,CreatedOn TEXT,UpdatedOn TEXT,DeletedOn TEXT);
导致异常的语句,在SQLiteOpenHelper中:
@Override
public void onCreate(android.database.sqlite.SQLiteDatabase db) {
String CREATE_MESSAGES_TABLE =
"CREATE TABLE " + TABLE_MESSAGES + "("
+ COLUMN_UNIQUEID + " TEXT PRIMARY KEY,"
+ COLUMN_FROM + " TEXT,"
+ COLUMN_TO + " TEXT,"
+ COLUMN_SUBJECT + " TEXT,"
+ COLUMN_BODY + " TEXT,"
+ COLUMN_HANDLEDON + " TEXT,"
+ COLUMN_ISREAD + " INTEGER,"
+ COLUMN_CREATEDON + " TEXT,"
+ COLUMN_UPDATEDON + " TEXT,"
+ COLUMN_DELETEDON + " TEXT"
+ ");";
String CREATE_CONTACTS_TABLE =
"CREATE TABLE " + TABLE_CONTACTS + "("
+ COLUMN_UNIQUEID + " TEXT PRIMARY KEY,"
+ COLUMN_NAME + " TEXT,"
+ COLUMN_EMAIL + " TEXT,"
+ COLUMN_CREATEDON + " TEXT,"
+ COLUMN_UPDATEDON + " TEXT,"
+ COLUMN_DELETEDON + " TEXT"
+ ");";
db.execSQL(CREATE_MESSAGES_TABLE);
db.execSQL(CREATE_CONTACTS_TABLE);
}
答案 0 :(得分:2)
您正在使用受保护的关键字,例如“from”和“to”作为表名,这在SQLite中是不允许的: