我正在尝试建立一个数据库并分别命名各列,但是在第16行出现了一个错误,其中PRIMARY KEY说“')'或预期的昏迷得到了'_title'
public class MyDBHandler extends SQLiteOpenHelper{
private static final int DATABASE_VERSION=1;
private static final String DATABASE_NAME="movies.db";
public static final String TABLE_PRODUCTS="_movies";
public static final String COLUMN_ID="_id";
public static final String COLUMN_TITLE="_title";
public static final String COLUMN_DATERELEASED="_dateReleased";
public static final String COLUMN_FILENAME="_fileName";
public MyDBHandler(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
super(context, name, factory, version);
}
@Override
public void onCreate(SQLiteDatabase db) {
//INFORMATION ABOUT EACH COLUMN FOR THE TABLE
String query="CREATE TABLE "+TABLE_PRODUCTS+"("+
COLUMN_ID+" INTEGER PRIMARY KEY AUTOINCREMENT "+
COLUMN_TITLE+" TEXT "+
COLUMN_DATERELEASED+"TEXT "+
COLUMN_FILENAME+" TEXT "
+" ); ";
db.execSQL(query);
}
答案 0 :(得分:1)
您的查询错误,您忘记设置逗号。 您的查询就是这样
@Override
public void onCreate(SQLiteDatabase db) {
//INFORMATION ABOUT EACH COLUMN FOR THE TABLE
String query="CREATE TABLE "+TABLE_PRODUCTS+"("+
COLUMN_ID+" INTEGER PRIMARY KEY AUTOINCREMENT, "+
COLUMN_TITLE+" TEXT, "+
COLUMN_DATERELEASED+"TEXT, "+
COLUMN_FILENAME+" TEXT "
+" ); ";
db.execSQL(query);
}
答案 1 :(得分:0)
您忘记在每列之后添加逗号。您的查询字符串应为
String query="CREATE TABLE "+TABLE_PRODUCTS+"("+
COLUMN_ID+" INTEGER PRIMARY KEY AUTOINCREMENT, "+
COLUMN_TITLE+" TEXT, "+
COLUMN_DATERELEASED+"TEXT, "+
COLUMN_FILENAME+" TEXT "
+" )";