我目前正在尝试使用我的 android 手机访问我的数据库,但它不起作用。它确实适用于模拟器。所以我想知道是否需要通过使用将数据复制到手机的内存中
try{
InputStream myInput = myContext.getAssets().open(DB_NAME);
// Path to the just created empty db
String outFileName = DB_PATH + DB_NAME;
//Open the empty db as the output stream
OutputStream myOutput = new FileOutputStream(outFileName);
//transfer bytes from the inputfile to the outputfile
byte[] buffer = new byte[1024];
int length;
while ((length = myInput.read(buffer))>0){
myOutput.write(buffer, 0, length);
}
//Close the streams
myOutput.flush();
myOutput.close();
myInput.close();
}catch(SQLiteException e){
另一个问题是我没有使用“SQLiteOpenHelper”,那么上面的方法仍然有效吗?我只是做了一个
private final String DB_NAME = "MemberData";
private final String TABLE_NAME = "MemberDB";
sampleDB = this.openOrCreateDatabase(DB_NAME, MODE_PRIVATE, null);
Cursor c = sampleDB.rawQuery("SELECT companyNameEng FROM " +
TABLE_NAME + " ORDER BY companyNameEng ASC", null);