简体   繁体   中英

How can i use onUpgrade Method?

In my Android project, I put the table I created using DB Browser for SQlite into the assets folder. I can connect to the database and retrieve the necessary information. I would like to ask you to update the database on the computer and put it in the assets folder and update it with the onUpgrade metadata. How can I do that?

public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
Log.d(LOG_TAG, " --- onUpgrade database from " + oldVersion
+ " to " + newVersion + " version --- ");
if (oldVersion == 1 && newVersion == 2)
{
this.getReadableDatabase();
try {
copyDataBase();
} catch (IOException e) {

throw new Error("Veritabany kopyalanamady");

}
}

The code didn't work for me.

if (oldVersion<newVersion){
    this.getReadableDatabase();
    try {
    copyDataBase();
    } catch (IOException e) {
        throw new Error("Veritabany kopyalanamady");
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM