안드로이드 개발 질문/답변
(글 수 45,052)
** 전략 SQLiteOpenHelper mHelper; SQLiteDatabase db; Cursor cursor; String FILE_PATH = "/data/data/**패키지명**/databases/"; String FILE_NAME = "데이터베이스.db"; String FILE = FILE_PATH + FILE_NAME; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); copydb(**액티비티명**.this); db.openDatabase(FILE, null, SQLiteDatabase.OPEN_READONLY); cursor = db.query("_order", new String[]{"row"}, null, null, null, null, null); //여기서 안넘어가네요 ㅠㅠ //cursor = db.rawQuery("SELECT * FROM _order", null); //startManagingCursor(cursor); setContentView(R.layout.main); } //To copy Database File from Assets Folder to Databases Folder public void copydb(Activity act){ AssetManager am = act.getAssets(); String FILE_PATH = "/data/data/**패키지명**/databases"; String FILE_NAME = "데이터베이스.db"; //File Path File outDir = null; File outFile = null; outDir = new File(FILE_PATH); outDir.mkdirs(); outFile = new File(outDir, FILE_NAME); InputStream is = null; OutputStream os = null; int size; try{ is = am.open("데이터베이스.db"); size = is.available(); outFile.createNewFile(); os = new FileOutputStream(outFile); byte[] buffer = new byte[size]; is.read(buffer); os.write(buffer); is.close(); os.close(); }catch(Exception e){ e.printStackTrace(); }finally{ try{ is.close(); os.close(); }catch(IOException e){ e.printStackTrace(); } } } }
- 제일 처음에 Assets폴더에 있는 데이터베이스.db를 /data/data/**패키지명**/databases/에 옮기고 나서 문제가....
데이터베이스 열기가 제대로 된건지도 잘 모르겠구요
커서랑 연결하는 방법도 제대로 된건지 모르겠어요 ㅠㅠ
이걸로 계속 헤매는 중이에요 ㅠㅠ