我在 SQLCiper 中尝试一件事。
这个东西在 SQLite 数据库中是成功的SD-CARD
1-创建了一个应用程序firstApp
。与数据库SD-CARD
2-创建第二个应用程序secondApp
。
我正在尝试在我的第二个应用程序中从 SD-CARD 读取数据。
编辑:- 我在 SDCARD 中的数据库。
public class SdcardCipherDataBase extends SQLiteOpenHelper
{
public static final String DATABASE_FILE_PATH = "/sdcard";
public static final String DATABASE_NAME = "sdCipherDatabase";
public final static String NAME ="name";
public final static String ADDRESS ="address";
public final static String CITY ="city";
public SdcardCipherDataBase(final Context context) {
super(context,Environment.getExternalStorageDirectory()+File.separator+DATABASE_FILE_PATH + File.separator + DATABASE_NAME, null, 1);
}
@Override
public void onCreate(SQLiteDatabase db) {
try
{
db.execSQL( "CREATE TABLE information(_id INTEGER PRIMARY KEY AUTOINCREMENT,name TEXT, address TEXT,city TEXT);");
}
catch (SQLiteException ex)
{
Log.e("Hello", "error -- " + ex.getMessage(), ex);
}
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated method stub
db.execSQL("DROP Table mylistdata");
onCreate(db);
}
}
我在同一个应用程序中使用这个数据库:-
public void databasCollection()
{
SQLiteDatabase.loadLibs(this);
File file = getDatabasePath("/mnt/sdcard/sdcard/sdCipherDatabase");
file.mkdir();
file.delete();
db = SQLiteDatabase.openOrCreateDatabase(file, "myapp", null);
sdb = new SdcardCipherDataBase(this);
sdb.getWritableDatabase("myapp");
ContentValues c = new ContentValues();
c.put(SdcardCipherDataBase.NAME,"monty");
c.put(SdcardCipherDataBase.ADDRESS,"BTM");
c.put(SdcardCipherDataBase.CITY,"Bangalore");
db.insert("information", SdcardCipherDataBase.NAME, c);
db.close();
}
但我也想在其他应用程序中使用相同的数据库。
我正在尝试做这样的事情
public void databaseFromOtherApp()
{
SQLiteDatabase.loadLibs(this);
File file = getDatabasePath("/mnt/sdcard/sdcard/sdCipherDatabase");
db = SQLiteDatabase.openOrCreateDatabase(file, "myapp", null);
dh = new DatabaseHelper(this);
Cursor cursor = db.rawQuery("select * from information", null);
cursor.moveToFirst();
String s = cursor.getString(cursor.getColumnIndex(NAME));
Toast.makeText(this,"Name is "
+s, Toast.LENGTH_LONG).show();
cursor.close();
db.close();
}
但显示错误。
Caused by: net.sqlcipher.database.SQLiteException: no such table: information: , while compiling: select * from information