编译SQLite DB(创建表)时出现语法错误我的查询有什么问题?

时间:2016-01-16 06:28:19

标签: android sqlite

        public void onCreate(SQLiteDatabase db) {
            String query = "CREATE TABLE " + TABLE_INFO + "(" +
            COLUMN_ID + " INTEGER PRIMARY KEY " +
            COLUMN_DATE + " TEXT " +
            COLUMN_DOCNAME + " TEXT " +
            COLUMN_SYMP + " TEXT " +
            COLUMN_DIGNO + " TEXT " +
            COLUMN_MEDS + " TEXT " +
            ");";
     db.execSQL(query);

这有什么问题?获取AndroidRuntime:

FATAL EXCEPTION: main android.database.sqlite.SQLiteException:                                  
                 near "date": syntax error: ,
 while compiling: CREATE TABLE info(_id INTEGER PRIMARY KEY 
                   date TEXT 
                   docName TEXT symp TEXT digno TEXT meds TEXT );

错误。

请帮忙

2 个答案:

答案 0 :(得分:1)

每个列后的查询中都有逗号,请更改查询字符串,如下所示:

String query = "CREATE TABLE " + TABLE_INFO + "(" +
        COLUMN_ID + " INTEGER PRIMARY KEY, " +
        COLUMN_DATE + " TEXT, " +
        COLUMN_DOCNAME + " TEXT, " +
        COLUMN_SYMP + " TEXT, " +
        COLUMN_DIGNO + " TEXT, " +
        COLUMN_MEDS + " TEXT " +
        ");";

答案 1 :(得分:0)

你缺少逗号。添加它。