我在数据库中更改了表会议和分钟的某些字段,并将数据库版本从1更改为3.当我在模拟器上运行应用程序时,我得到表仍然存在的错误。我怎么放下桌子?
log cat:
05-31 15:30:32.338: E/AndroidRuntime(20347): android.database.sqlite.SQLiteException: table Meeting already exists: , while compiling: create table Meeting (_id integer primary key autoincrement, meet text not null, venue text not null, agenda text not null, time text not null, date text not null, phoneNo text not null, email text not null);
05-31 15:30:32.338: E/AndroidRuntime(20347): at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method)
数据库代码:
public class DBUserAdapter
{
public static final String KEY_ROWID = "_id";
private static final String TAG = "DBAdapter";
public static final String KEY_ROWID2 = "_id1";
private static final String DATABASE_NAME = "usersdb";
private static final String DATABASE_TABLE = "Meeting";
private static final String DATABASE_TABLE1 = "minutes";
private static final int DATABASE_VERSION = 3;
private static final String DATABASE_CREATE =
"create table Meeting (_id integer primary key autoincrement, "
+ "meet text not null, "
+ "venue text not null, "
+ "agenda text not null, "
+ "time text not null, "
+ "date text not null, "
+ "phoneNo text not null, "
+ "email text not null);";
private static final String MINUTES_TABLE_CREATE =
"create table minutes (_id1 integer primary key autoincrement, "
+ "meet text not null, "
+ "minutes text not null,";
private SQLiteDatabase db;
public DBUserAdapter(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)
{
db.execSQL(DATABASE_CREATE);
db.execSQL(MINUTES_TABLE_CREATE);
}
@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 DATABASE_TABLE ");
db.execSQL("DROP TABLE IF EXISTS DATABASE_TABLE1 ");
onCreate(db);
}
}
我很困惑onupgrade()是如何工作的? 我该怎么办?放下桌子?
答案 0 :(得分:1)
Change this
db.execSQL("DROP TABLE IF EXISTS " + DATABASE_TABLE);
与其他表同上。您希望DATABASE_TABLE的值不是字符串“DATABASE_TABLE”