애셋 폴더에 sqlite db가 있습니다. 앱을 처음 실행하기 위해 "data/data/databases"경로로 복사합니다.Android : 진저 브레드 전에 애셋에서 sqlite 복사
진저 브레드에서 모든 장치에서 정상적으로 작동하지만 이전 버전에서는 데이터베이스를 쿼리 할 때 테이블을 찾을 수없는 예외가 발생합니다. 실제로 데이터베이스 폴더에있는 db는 비어 있습니다. android_metadata 테이블 만 포함합니다. 여기
내가 DB를 복사하는 데 사용하는 두 가지 방법 : 여기
public static void copyDBInMemoryIfNeeded(Context ctx, String pkgName) {
try {
String destPath = ctx.getFilesDir().getParentFile().getPath() + "/databases";
File f = new File(destPath);
if (!f.exists()) {
f.mkdirs();
f.createNewFile();
copyDBInMemory(ctx.getAssets().open("mydb.sqlite"),
new FileOutputStream(destPath));
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
private static void copyDBInMemory(InputStream inputStream, OutputStream outputStream)
throws IOException {
// ---copy 1K bytes at a time---
byte[] buffer = new byte[1024];
int length;
while ((length = inputStream.read(buffer)) > 0) {
outputStream.write(buffer, 0, length);
}
inputStream.close();
outputStream.close();
}
및 내 DBAdapter 클래스 :
public class DBAdapter {
final Context context;
DatabaseHelper DBHelper;
SQLiteDatabase db;
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) {
}
@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 contacts");
onCreate(db);
}
}
public DBAdapter open() throws SQLException {
db = DBHelper.getWritableDatabase();
return this;
}
public void close() {
DBHelper.close();
} }
SQL Server 자산 폴더의 크기는 얼마나됩니까? – hardartcore
4.7 메가 바이트 – TheModularMind