2012-12-03 3 views
0

새로운 데이터베이스 파일로 저장소의 응용 프로그램을 업데이트하려고하는데 .... 실행하려고 할 때 오류가 발생했습니다 ...어떻게 내 안드로이드 데이터베이스 파일을 대체 할 수 있습니까?

내 코드에 문제가 있다고 생각합니다. ..

class DatabaseUtilities { 
public static void createDatabaseIfNotExists(Context context) 
      throws IOException { 
     boolean createDb = false; 
     File dbDir = new File(AppConstants.DB_PATH); 
     File dbFile = new File(AppConstants.DB_PATH + AppConstants.DB_NAME); 
     if (!dbDir.exists()) { 
      dbDir.mkdir(); 
      createDb = true; 
     } else if (!dbFile.exists()) { 
      createDb = true; 
     } else { 
      boolean doUpgrade = true; 

      if (doUpgrade) { 
       dbFile.delete(); 
       createDb = true; 

      } 
     } 

     if (createDb) { 
      InputStream myInput = context.getAssets().open("altibbi.db"); 
      OutputStream myOutput = new FileOutputStream(dbFile); 
      byte[] buffer = new byte[1024]; 
      int length; 
      while ((length = myInput.read(buffer)) > 0) { 
       myOutput.write(buffer, 0, length); 
      } 
      myOutput.flush(); 
      myOutput.close(); 
      myInput.close(); 
     } 
    } 

    public static SQLiteDatabase getDatabase() { 
     return SQLiteDatabase.openDatabase(AppConstants.DB_PATH 
       + AppConstants.DB_NAME, null, 
       SQLiteDatabase.NO_LOCALIZED_COLLATORS); 
    } 

} 
+0

답변을 찾으려면 여기를 클릭하십시오. http://stackoverflow.com/questions/9109438/how-to-use-an-existing-database-with-an-android-application/9109728#9109728 –

+1

whats the error? – zennon

+0

은 Logcat에서 오류를 공유합니다 – Androider

답변

0

SQLiteOpenHelper하고 onUpgrade() 콜백을 사용하여 코드를 단순화하지?

+1

저를 도우려는 각자에게 감사드립니다 .... 문제가 해결되었습니다 ... 나는 새 데이터베이스의 이름을 변경하고 오래된 것을 삭제합니다. – aziz

관련 문제