0

我已经更改了数据库中的某些表会议和分钟字段,并将数据库版本从 1 更改为 3。当我在模拟器上运行应用程序时,我收到表仍然存在的错误。我如何放下桌子?

日志猫:

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() 是如何工作的?我应该怎么办?放下桌子?

4

1 回答 1

1
Change this    
    db.execSQL("DROP TABLE IF EXISTS " + DATABASE_TABLE); 

其他表同上。您想要 DATABASE_TABLE 的值而不是字符串“DATABASE_TABLE”

于 2013-05-31T10:21:29.073 回答