【发布时间】:2013-12-04 10:40:09
【问题描述】:
我正在尝试在我的 android 应用程序中附加一个现有的 sqlcipher 数据库(加密),但是在将其复制到我的目录后,它无法使用“SQLiteDatabase.openDatabase(...)”打开
我在普通 sqlite 中尝试了代码,它工作正常,但是当我使用 sqlcipher API 时,我收到了这个错误消息
//CREATE TABLE android_metadata failed
//Failed to setLocale() when constructing, closing the database
// net.sqlcipher.database.SQLiteException: file is encrypted or is not a database
我在 SQLiteOpenHelper 类中使用了以下代码:
if(!dbExist1)
{
this.getWritableDatabase(password);
this.openDatabase();
try
{
this.close();
copyDataBase();
}
catch (IOException e)
{
throw new Error("Error copying database");
}
}
public SQLiteDatabase openDatabase() throws SQLException {
String DBPath = DATABASE_PATH + DATABASE_NAME;
myDataBase = SQLiteDatabase.openDatabase(DBPath, password, null,
SQLiteDatabase.NO_LOCALIZED_COLLATORS);
return myDataBase;
}
我在 Activity 类中使用了以下代码:
SQLiteDatabase.loadLibs(this);
DataBaseHelper myDbHelper ;
myDbHelper = new DataBaseHelper(this);
SQLiteDatabase db=myDbHelper.openDatabase();
我尝试使用this solution,但还是同样的错误
块引用
【问题讨论】: