本文介绍了SQLite中的Android创建表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图创建在我的Android SQLite数据库三个表,但表不会创建,只是数据库。使用观看的DDMS,创建数据库,但是当我使用SQLite浏览器来查看,没有表仅创建元数据。
I'm trying to create three tables for my sqlite database in android, but the tables won't create, just the database. Using viewing the DDMS, the database is created, but when I view it using SQLite Browser, no tables are created only the metadata.
下面是我如何做到这一点:
Here's how I do it:
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年底不应该有一个逗号。
You have a comma at the end of DATABASE_CREATE that shouldn't be there.
... weightclass VARCHAR not null,);"
应
... weightclass VARCHAR not null);"
这篇关于SQLite中的Android创建表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!