gpt4 book ai didi

android - 在 sqlite android 中创建表

转载 作者:行者123 更新时间:2023-11-29 18:04:58 25 4
gpt4 key购买 nike

我正在尝试在 android 中为我的 sqlite 数据库创建三个表,但不会创建表,只会创建数据库。使用查看 DDMS,创建了数据库,但是当我使用 SQLite 浏览器查看它时,没有创建任何表,只有元数据。

这是我的做法:

private static final String DATABASE_NAME = "fgtDB";
private static final String DATABASE_TABLE = "profiles";
private static final String DATABASE_TABLE2 = "routines";
private static final String DATABASE_TABLE3 = "UserRoutines";
private static final int DATABASE_VERSION = 3;

private static final String DATABASE_CREATE =
"create table if not exists profiles (_id integer primary key autoincrement, "
+ "firstname VARCHAR not null, age VARCHAR not null, "
+ "heightft VARCHAR not null, heightin VARCHAR not null, weight VARCHAR not null, duration VARCHAR not null, bmi VARCHAR not null, weightclass VARCHAR not null,);";

private static final String DATABASE_CREATE2 =
"create table if not exists routines (_id integer primary key autoincrement, "
+ "weightclass VARCHAR not null, musclegroup VARCHAR not null, "
+ "exercise VARCHAR not null, numberofsets VARCHAR not null, numberofrepitition VARCHAR not null, day VARCHAR not null);";

private static final String DATABASE_CREATE3 =
"create table if not exists UserRoutines (userid integer not null, "
+ "musclegroup VARCHAR not null, day VARCHAR not null"
+ "exercise VARCHAR not null, numberofsetsleft VARCHAR not null, numeberofrepitition VARCHAR not null, isdone VARCHAR not null);";

private final Context context;

private DatabaseHelper DBHelper;
private SQLiteDatabase db;

public DBAdapter(Context ctx)
{
this.context = ctx;
DBHelper = new DatabaseHelper(context);
}

private static class DatabaseHelper extends SQLiteOpenHelper
{
DatabaseHelper(Context context)
{
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}

@Override
public void onCreate(SQLiteDatabase db)
{
try
{
db.execSQL(DATABASE_CREATE);
db.execSQL(DATABASE_CREATE2);
db.execSQL(DATABASE_CREATE3);
}
catch(SQLException e)
{
e.printStackTrace();
}
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
{
Log.w(TAG, "Upgrading database from version " + oldVersion
+ " to "
+ newVersion + ", which will destroy all old data");
db.execSQL("DROP TABLE IF EXISTS profiles");
onCreate(db);
}
}

有什么想法吗?

最佳答案

您在 DATABASE_CREATE 的末尾有一个不应该存在的逗号。

...  weightclass VARCHAR not null,);"

应该是

...   weightclass VARCHAR not null);"

关于android - 在 sqlite android 中创建表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13851857/

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