Suddenly, it seems like the database used by my application is corrupted. I did not change the database structure, but I redeployed the application several times on my device today.
This throws the following exception.
E/Database(14281): CREATE TABLE android_metadata failed err=26 ..
E/Database(14281): Failed to setLocale() when constructing, closing the database
E/Database(14281): android.database.sqlite.SQLiteException: file is encrypted or is not a database
E/Database(14281): at android.database.sqlite.SQLiteDatabase.native_setLocale(Native Method)
E/Database(14281): at android.database.sqlite.SQLiteDatabase.setLocale(SQLiteDatabase.java:1848)
E/Database(14281): at android.database.sqlite.SQLiteDatabase.<init>(SQLiteDatabase.java:1798)
E/Database(14281): at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:798)
E/Database(14281): at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:857)
E/Database(14281): at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:850)
E/Database(14281): at android.app.ApplicationContext.openOrCreateDatabase(ApplicationContext.java:539)
E/Database(14281): at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:193)
E/Database(14281): at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:98)
E/Database(14281): at com.ecs.android.gps.storage.DBAdapter.open(DBAdapter.java:75)
The database is initialized using the SQLLiteOpenHelper class.
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)
{
db.execSQL(DATABASE_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 location_history");
onCreate(db);
}
}
- I basically open / close the database and cursors for each operation.
- Some articles point this way, but for an Android app, does it make sense to open a database connection all the time?
- I can imagine it bring much more resources to open / close it every time.
- There are several activities and services that access the database. (maybe at the same time)
, , , ?
, - concurrency ( , / / ). , SQLite , (mysql - oracle), , ,.....