0

i'm trying to update my application in the store with new database file .... but i got error when i'm trying to run it ...

i think there is a problem in my code ...

    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);
    }

 }
Padma Kumar
  • 19,893
  • 17
  • 73
  • 130
aziz
  • 67
  • 1
  • 7
  • Find your answer here: http://stackoverflow.com/questions/9109438/how-to-use-an-existing-database-with-an-android-application/9109728#9109728 – Yaqub Ahmad Dec 03 '12 at 12:57
  • share your errors from Logcat – Androider Dec 03 '12 at 13:09
  • it's can't replace the old database with the new 1 – aziz Dec 03 '12 at 13:28
  • this is the error Re-installation failed due to different application signatures. You must perform a full uninstall of the application. WARNING: This will remove the application data! Please execute 'adb uninstall com.altibbi.directory' in a shell – aziz Dec 03 '12 at 14:00

1 Answers1

0

Why don't you simplify your code by using SQLiteOpenHelper and its onUpgrade() callback?

Dheeraj Vepakomma
  • 26,870
  • 17
  • 81
  • 104
  • 1
    thanks for every one who try to help me .... the problem solved ... i just change the name of the new database .. and delete the old one – aziz Dec 04 '12 at 13:35