Skip to content Skip to sidebar Skip to footer

Sqlitereadonlydatabaseexception: Attempt To Write A Readonly Database

Just changed my data that are hard-code into database to using SQLite Database Browser. Before I changed all my query works fine but errors occurs when I changed. I can't do those

Solution 1:

You need to make a writable database if you want to insert values in database need to add these lines in constructor

DBHelperhelper=newDBHelper (mCtx);
                this.db = helper.getWritableDatabase();

      publicRestaurant(Context c)
{   
    myContext = c;

                DBHelperhelper=newDBHelper (mCtx);
            this.db = helper.getWritableDatabase();
}           

Solution 2:

You cannot write to a database that is stored in your assets folder as that is part of your apk and cannot be changed.

When your app runs you should check for the existence of a database (in the normal databases folder) and if it does not exist, copy the database from your assets folder and use that instead.

See these links for more info.

http://www.devx.com/wireless/Article/40842

Ship an application with a database

Solution 3:

publicvoidopenDataBase()throws SQLException{

    //Open the databaseStringmyPath= DB_PATH + DATABASE_NAME;
    ourDatabase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY);

}

You must change SQLiteDatabase.OPEN_READONLY to SQLiteDatabase.OPEN_READWRITE, because OPEN_READONLY only allows to read not write.

Post a Comment for "Sqlitereadonlydatabaseexception: Attempt To Write A Readonly Database"