Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6988969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:09:05+00:00 2026-05-27T19:09:05+00:00

How to upgrade read only sqlite database I have tried to change to SQLiteDatabase.OPEN_READWRITE);

  • 0

How to upgrade read only sqlite database

I have tried to change to SQLiteDatabase.OPEN_READWRITE); and getReadableDatabase();
the result still the same.


When I want to upgrade my sqlite datatbase from version 1 to 2 , I got this error :

SQLiteException: Can't upgrade read-only database from version X to Y

In the 1st verison of my apps , I use this code :

private static final String DB_NAME = "this_the_database";
private final Context context;
private static final int DATABASE_VERSION = 1;

public DatabaseHelper(Context context) {
    super(context, DB_NAME, null, DATABASE_VERSION);
    this.context = context;

    String path = context.getDatabasePath(DB_NAME).getAbsolutePath();
    SQLiteDatabase db = null;
    try {
        db = SQLiteDatabase.openDatabase(path, null,
                SQLiteDatabase.OPEN_READONLY);
    } catch (SQLiteException e) { // DB not found       
        db = getReadableDatabase();
        db.close();
        // Copy DB from asset folder.
        copyDatabase(path);
    }

    if (db != null) {
        db.close();
    }
}

when I decided to upgarde the database using this , it crashed

@Override
public void onCreate(SQLiteDatabase db) {
    new DatabaseHelper(context).getReadableDatabase();
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    db.execSQL("DROP TABLE IF EXISTS " + DB_NAME);
    onCreate(db);
}

Ref: http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T19:09:06+00:00Added an answer on May 27, 2026 at 7:09 pm

    Why do you use SQLiteDatabase.openDatabase? It should be sufficient to have just the call to super(..) in the DatabaseHelper constructor. The getReadableDatabase() can be in an open() method or can be called by the activity opening the database.
    In the apidemos, there is a LoaderThrottle example that shows how to use the Android SQLite database.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sometimes you need to upgrade the database with many rows that you have in
My iPhone app will have read-only system data AND read/write user data (stored either
A vendor has a data database (read only) that gets sent to us via
I'm using read/write locks on Linux and I've found that trying to upgrade a
Having to upgrade a database schema makes installing a new release of software a
I have a database which is part of a closed system and the end-user
I want to bulk insert about 700 records into the Android database on my
I'm using sqlite as a datasource in an iPhone app. I have two questions
I have read the documentation about automatic /lightweight migration for Core Data models -
I have an Android App with a pre-built SQLite DB packaged with it. However,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.