错误:android.database.sqlite.SQLiteException:near“=”:语法错误(代码1):,同时编译

时间:2015-11-16 11:47:40

标签: android mysql sqlite

我在检索本地数据库数据时遇到以下错误:

android.database.sqlite.SQLiteException: near "=": syntax error (code 1): , while compiling: SELECT EVENT_USER_ID,EVENT_ID,RINGEE_USER_ID,IS_INVITED,IS_ATTENDING,IS_DELETE FROM user_relationWHERE _ID =1

user_relation表的查询在下面,

public static abstract class UserRelationTable {
    public static final String TABLE_NAME = "user_relation";
    public static final String COL1_EVENT_USER_ID = "EVENT_USER_ID";
    public static final String COL2_EVENT_ID = "EVENT_ID";
    public static final String COL3_RINGEE_USER_ID = "RINGEE_USER_ID";
    public static final String COL4_IS_INVITED = "IS_INVITED";
    public static final String COL5_IS_ATTENDING = "IS_ATTENDING";
    public static final String COL6_IS_DELETE = "IS_DELETE";

    public static final String CREATE_TABLE = "CREATE TABLE " + TABLE_NAME + "(" + _ID + " INTEGER PRIMARY KEY," + COL1_EVENT_USER_ID + INTEGER_TYPE + COMMA_SEP + COL2_EVENT_ID + INTEGER_TYPE
            + COMMA_SEP + COL3_RINGEE_USER_ID + INTEGER_TYPE + COMMA_SEP + COL4_IS_INVITED + INTEGER_TYPE + COMMA_SEP + COL5_IS_ATTENDING + INTEGER_TYPE + COMMA_SEP + COL6_IS_DELETE + INTEGER_TYPE + ")";

    public static final String DELETE_TABLE = "DROP TABLE IF EXISTS " + TABLE_NAME;

    public static final String RETRIVE_ALL_USER_DATA = "SELECT " + COL1_EVENT_USER_ID + COMMA_SEP + COL2_EVENT_ID + COMMA_SEP + COL3_RINGEE_USER_ID + COMMA_SEP + COL4_IS_INVITED + COMMA_SEP + COL5_IS_ATTENDING + COMMA_SEP
            + COL6_IS_DELETE + " FROM " + TABLE_NAME + "WHERE _ID =";
}

如何解决此错误有助于我提前感谢。

3 个答案:

答案 0 :(得分:2)

WHERE之前添加空格:

public static final String RETRIVE_ALL_USER_DATA = "SELECT " + COL1_EVENT_USER_ID + COMMA_SEP + COL2_EVENT_ID + COMMA_SEP + COL3_RINGEE_USER_ID + COMMA_SEP + COL4_IS_INVITED + COMMA_SEP + COL5_IS_ATTENDING + COMMA_SEP
            + COL6_IS_DELETE + " FROM " + TABLE_NAME + " WHERE _ID =";

答案 1 :(得分:0)

试试这个,

public static final String RETRIVE_ALL_USER_DATA = "SELECT " + COL1_EVENT_USER_ID + COMMA_SEP + COL2_EVENT_ID + COMMA_SEP + COL3_RINGEE_USER_ID + COMMA_SEP + COL4_IS_INVITED + COMMA_SEP + COL5_IS_ATTENDING + COMMA_SEP
            + COL6_IS_DELETE + " FROM " + TABLE_NAME + " WHERE _ID =";

您没有在tablename之后给出空格,这就是发生此错误的原因。

答案 2 :(得分:0)

代码中的

字符串RETRIVE_ALL_USER_DATA

“WHERE _ID =” 倾向于 “WHERE _ID =” 始终标记为 数据库

简单易行

SPACE After SELECT,CREATE,DELETE,UPDATE等......

和SPACE 两者 一侧 WHERE,LIKE,IN,FROM等......