gpt4 book ai didi

java - 在android上使用SQLITE出现列约束错误

转载 作者:行者123 更新时间:2023-12-02 10:42:22 25 4
gpt4 key购买 nike

我正在尝试设置一个数据库并分别命名列,但我在第 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);
}

最佳答案

您的查询错误,您忘记设置逗号。您的查询是这样的

@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);
}

关于java - 在android上使用SQLITE出现列约束错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52847938/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com