创建db时出现sqlite异常

时间:2016-03-03 13:25:46

标签: android sqliteopenhelper

我尝试使用以下sqlite查询创建表。

JSONArray jsonArray = new JSONArray();

JSONObject pnObj_reeferleft = new JSONObject();

pnObj_reeferleft.put("comments", reeferleft_cm);

pnObj_reeferleft.put("section", reeferleft_section);

pnObj_reeferleft.put("pictures", reeferleft);

jsonArray.put(pnObj_reeferleft);    

JSONObject jsonParam = new JSONObject();

jsonParam.put("hash", "somedata");

jsonParam.put("media", jsonArray);

我使用以下代码将元素添加到db,

private static final String CREATE_EMPLOYEE_TABLE = "CREATE TABLE " + TABLE_EMPLOYEE + "("
            + KEY_DOMAIN_ID + " INTEGER PRIMARY KEY,"
            + KEY_FROM + " TEXT,"
            + KEY_TO + " TEXT" + ")";

private static final String CREATE_GROUPS_TABLE = "CREATE TABLE " + TABLE_GROUPS + "("
        + KEY_USERID + " INTEGER PRIMARY KEY,"
        + KEY_NAME + " TEXT,"
        + KEY_SESSION_TOKEN + " TEXT,"
        + KEY_GROUP_ID + " TEXT,"
        + KEY_GROUP_NAME + " TEXT" + ")";`

这两个查询都会抛出以下错误消息

  

android.database.sqlite.SQLiteException:near“group”:语法错误   (代码1):,编译时:CREATE TABLE组(userId INTEGER PRIMARY   KEY,名称TEXT,sessionToken TEXT,groupId TEXT,groupName TEXT)

2 个答案:

答案 0 :(得分:7)

重命名变量

String TABLE_GROUPS = "group"

类似

String TABLE_GROUPS = "groups"

  

groupsql中的保留关键字。

Check here the list of reserved keywords in SQLite

答案 1 :(得分:2)

您的表格名称不能是群组,群组是Sqlite中的关键字,收件人也是关键字

请参阅此处列出的Sqlite中的其他关键字.. https://www.sqlite.org/lang_keywords.html