我正在创建一个可在模拟器上运行但不在设备上运行的表。我收到此错误消息:
Failure 1 (near "(": syntax error) on 0x2d69a8 when preparing 'CREATE TABLE request(requestidINTEGER PRIMARY KEY,longitudefromDECIMAL(10,5),lattitudefromDECIMAL(10,5),phoneINTEGER)
我正在创建这样的表:
String CREATE_REQUEST_TABLE= "CREATE TABLE " + TABLE_REQUEST + "("
+ KEY_REQUESTID + "INTEGER PRIMARY KEY,"
+ KEY_LONGITUDEFROM + "DECIMAL(10,5),"
+ KEY_LATTITUDEFROM + "DECIMAL(10,5),"
+ KEY_TO + "TEXT,"
+ KEY_DEPARTURETIME + "TIME,"
+ KEY_ARRIVALTIME + "TIME,"
+ KEY_DESCRIPTION + "TEXT,"
+ KEY_PHONE + "INTEGER" + ")";
db.execSQL(CREATE_REQUEST_TABLE);
答案 0 :(得分:2)
您的请求中没有空格。在键之前和之后添加空格:
String CREATE_REQUEST_TABLE= "CREATE TABLE " + TABLE_REQUEST + " ("
+ KEY_REQUESTID + " INTEGER PRIMARY KEY, "
+ KEY_LONGITUDEFROM + " DECIMAL(10,5), "
+ KEY_LATTITUDEFROM + " DECIMAL(10,5), "
+ KEY_TO + " TEXT, "
+ KEY_DEPARTURETIME + " TIME, "
+ KEY_ARRIVALTIME + " TIME, "
+ KEY_DESCRIPTION + " TEXT, "
+ KEY_PHONE + " INTEGER" + ")";
答案 1 :(得分:1)
好吧,正如您在错误消息中看到的那样,KEY_REQUESTID + "INTEGER PRIMARY KEY,"
变为requestidINTEGER PRIMARY
而不是requestid INTEGER PRIMARY
。基本上,列名和列类型之间没有空格,这使得它们(作为SQLite)看起来像一个标记。
答案 2 :(得分:1)
尝试使用您的ID和" INTEGER PRIMARY KEY之间的空格,"
像;
KEY_REQUESTID + " INTEGER PRIMARY KEY,"