Android 在处理程序内部使用onUpgradeonUpgrade???
onUpgrade是在您更改数据库(即添加表)时使用的,因此现在有了新版本的数据库。你的:Android 在处理程序内部使用onUpgradeonUpgrade???,android,sqlite,android-sqlite,Android,Sqlite,Android Sqlite,onUpgrade是在您更改数据库(即添加表)时使用的,因此现在有了新版本的数据库。你的: private static final int DATABASE_VERSION = 1; 现在是 private static final int DATABASE_VERSION = 2; 因为数据库版本现在是更高更新的版本,所以调用OnUpgrade()方法并更新数据库。这基本上是因为cursor.close()而发生的; 因为在返回游标对象的计数之前要关闭游标对象。我建议您,在完成数据库工作
private static final int DATABASE_VERSION = 1;
现在是
private static final int DATABASE_VERSION = 2;
因为数据库版本现在是更高更新的版本,所以调用OnUpgrade()方法并更新数据库。这基本上是因为cursor.close()而发生的;
因为在返回游标对象的计数之前要关闭游标对象。我建议您,在完成数据库工作之前不要关闭数据库对象
SQLiteDatabase db;
db = this.getWritableDatabase();
or
db = this.getReadableDatabase();
以上两种方法都使用helper类为我们提供了数据库对象,并且使用这个对象我们可以对数据库执行不同的操作。但在您的场景中,我认为您在完成数据库操作之前关闭了数据库对象。在所有操作完成后,使用
db.close();
只需使用名为myDb.open()的行打开它。那就做你的工作,你好
myDb.open()
将升级数据库吗?正在删除表行,…?您节省了我的时间:)getReadableDatabase()或getWriteableDatabase()不适用于我。
public void closeDB() {
SQLiteDatabase db = this.getReadableDatabase();
if (db != null && db.isOpen())
db.close();
}
private static final int DATABASE_VERSION = 1;
private static final int DATABASE_VERSION = 2;
SQLiteDatabase db;
db = this.getWritableDatabase();
or
db = this.getReadableDatabase();
db.close();