SQLite异常查询错误

时间:2014-01-10 17:33:22

标签: android sqlite

有人可以告诉我这是否正确吗?

public static final String DATABASE_CREATE = ("CREATE TABLE" + TABLE_NAME + "(" +
                                            COLUMN_ID + "INTEGER PRIMARY KEY AUTOINCREMENT,"+ 
                                            COLUMN_TITLE + "text not null," + 
                                            COLUMN_CATEGORY + "text not null," + 
                                            COLUMN_IMAGE + "text not null);");

错误是SQLiteException

2 个答案:

答案 0 :(得分:4)

您在列和表名之间缺少空格。这是更正的查询:

"CREATE TABLE " + TABLE_NAME + "(" +
 COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT,"+ 
 COLUMN_TITLE + " text not null," + 
 COLUMN_CATEGORY + " text not null," + 
 COLUMN_IMAGE + " text not null);");

另外,在查询结束时要注意分号。这是非常有问题的 - 我的意思是在某些设备上这个符号可能会导致错误(更安全的是不使用它)。

希望我帮助你解决问题。

答案 1 :(得分:2)

COLUMN_TITLE + "text not null" this is your mistake, 

在列的数据类型中添加一个空格,如下所示

public static final String DATABASE_CREATE = ("CREATE TABLE" + TABLE_NAME + "(" +
                                            COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT,"+ 
                                            COLUMN_TITLE + " text not null," + 
                                            COLUMN_CATEGORY + " text not null," + 
                                            COLUMN_IMAGE + " text not null);");

您的列名与其数据类型之间缺少空格。