import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;



public class MySQLiteOpenHelper {

    String savePath = "/mnt/sdcard/firstaid.db";    // 에뮬, 폰 실행은 되나 db 업데이트가 되지 않음
    //String savePath = "/data/data/com.same/databases/firstaid.db";    // 에뮬가능, 폰에서는 강제종료
    
    Context ctx;
    
    public SQLiteDatabase createDatabase(){
        
        SQLiteDatabase db;
                
        db = SQLiteDatabase.openDatabase(savePath, null, 0 );
        
        if( db == null ){
            
            try{
                InputStream myInput = ctx.getAssets().open("firstaid.db");
                String outFileName = "first.sqlite";
                OutputStream myOutput  = new FileOutputStream(savePath);
                byte[] buffer = new byte[1024];
                int length;
                while((length = myInput.read(buffer)) >0){
                    myOutput.write(buffer,0,length);
                    
                }
                myOutput.flush();
                myOutput.close();
                myInput.close();
                
                
            }catch(IOException e){
                //throw new Error("Error copying database");
                e.printStackTrace();                    
            }
            
            db = SQLiteDatabase.openDatabase(savePath, null, 0 );
        }//end if
         
        return db;
    }//end createDatabase
}//end class


 import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

public class MySQLiteHandler {

    private static String TABLE_NAME = "first_aid";
    Context ctx;
    
    MySQLiteOpenHelper helper;
    SQLiteDatabase db;
    
    public MySQLiteHandler(Context ctx) {
        db = new MySQLiteOpenHelper().createDatabase();
    }
    
    //open
    public static MySQLiteHandler open(Context ctx) {
        return new MySQLiteHandler(ctx);
    }
    
    public static void close() {
    }
    
    public long insert(String name, String address, String tel) {
        return 0;
    }
    
    public void delete() {
    }
    
    public int update(String _id, String name, String address, String tel) {
        return 0;
    }
    
    public Cursor selcet_double(String str1, String str2) {
        //Cursor c = db.query("first_aid", null, "title_num=?, type_num=?", new String[]{ str1, str2 }, null, null, null);
        Cursor c = db.query(TABLE_NAME, null, "title_num=" + "'" + str1 + "'" + "and" + " " + "type_num=" + "'" + str2 + "'", null, null, null, null);
        return c;
    }
    
}



db 관련 문제를 도저히 해결할 수 없어서 질문 올립니다..


파일 경로를

String savePath = "/data/data/com.same/databases/firstaid.db"; 로 하면

에뮬레이터에서는 DDMS에 databases 폴더가 생기면서 DB를 제대로 불러오는데

폰에서는 에러가 떠버리고

 

String savePath = "/mnt/sdcard/firstaid.db"; 로 했을 때

에뮬이나 폰에서 실행은 되나 변경된 db 내용을 불러오지 못합니다.

 

제 핸드폰이 아트릭스인데

DDMS로 확인을 해보니 현재 교체하려는 db 파일은 50kb 이나

핸드폰의 sdcard 경로에 있는 db 파일은 테스트용으로 사용했던 30kb로 그대로입니다.

 

혹시나해서 어플을 삭제한 뒤 sdcard에 있는 db 파일을 지우고 다시 설치했을 때 오류가 떴지만

DDMS 에서 db파일을 넣어주자 에러 없이 실행이 되었습니다.

 

아무래도 db 파일이 제대로 복사 및 교체가 되질않는거 같은데

 

해결방법을 못찾아서 다시 질문을 드립니다..