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 8690547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:55:29+00:00 2026-06-12T23:55:29+00:00

At the moment I am fiddling myself into working with sql databases in android

  • 0

At the moment I am fiddling myself into working with sql databases in android and created my first app. now i wanted to update this app and the including database in the assets folder. I overwrote the old database with the new one but on my phone it doesnt show the new entries.

It somehow is saving the old entries/queries or entirely the old Db. I checked on the net but couldnt really find a solution. Below my dbhelper code. Do i have to do something in onUpgrade or what would be the procedure?

Many thanks for helping!

public class DataBaseHelper extends SQLiteOpenHelper {
private static String DB_PATH;

private static String DB_NAME;

private SQLiteDatabase db_object;

private final Context context;

public DataBaseHelper(Context context, String db) {
    super(context, db, null, 80);
    this.context = context;
    DB_PATH = "/data/data/" + context.getPackageName() + "/databases/";
 //   DB_PATH = "/data/data/com.comp.appname/databases/";
    DB_NAME = "mydatabase.sqlite";
    try {
        createDataBase();
    } catch (IOException ioe) {
        throw new Error("Unable to create database");
    }
    try {
        openDataBase();
    } catch (SQLException sqle) {
        throw sqle;
    }
}

@Override
public void onCreate(SQLiteDatabase db) {
    // TODO Auto-generated method stub
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    // TODO Auto-generated method stub
}

public void createDataBase() throws IOException {
    boolean dbExist = checkDataBase();
    if (dbExist) {
    } else {
        this.getReadableDatabase();
        try {
            copyDataBase();
        } catch (IOException e) {
            throw new Error("Error copying database");
        }
    }
}

private boolean checkDataBase() {
    SQLiteDatabase checkDB = null;
    try {
        String myPath = DB_PATH + DB_NAME;
        checkDB = SQLiteDatabase.openDatabase(myPath, null,
                SQLiteDatabase.OPEN_READONLY);
    } catch (SQLiteException e) {
    }
    if (checkDB != null) {
        checkDB.close();
    }
    return checkDB != null ? true : false;
}

private void copyDataBase() throws IOException {
    InputStream myInput = context.getAssets().open(DB_NAME);
    String outFileName = DB_PATH + DB_NAME;
    OutputStream myOutput = new FileOutputStream(outFileName);
    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 void openDataBase() throws SQLException {
    String myPath = DB_PATH + DB_NAME;
    db_object = SQLiteDatabase.openDatabase(myPath, null,
            SQLiteDatabase.OPEN_READONLY);
}

@Override
public synchronized void close() {
    if (db_object != null)
        db_object.close();
    super.close();
}
}
  • 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-06-12T23:55:30+00:00Added an answer on June 12, 2026 at 11:55 pm

    I solved my own problem:

    in the onUpgrade method you need to put:

    mycontext.deleteDatabase(DB_NAME);
    

    in the databasehelper class i need to increase the version number like this for example:

    super(context, db, null, 84); 
    

    with mine it is 84 but basically you just need to increment it by 1, saying it is a higher version. Optimum would be if it exactly is your database version that you increment as well with every external edit of your db.

    Hope that will help others.

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

Sidebar

Related Questions

At this moment we are keeping all Entities and Mappings into same assembly. Our
So been fiddling around with this for a while now but still no luck.
There is a moment in my app, that I need to force to show
for the moment the script does like this: click on the link edit the
at the moment i have this <div id=beau> <div> <input type=text id=lun name=lun size=24
At the moment my application.js file looks like this: //= require_tree ./vendor //= require_directory
At the moment I am using this to call the TabHost activity to change
At the moment I’m working on a win32 application in Windows. I made a
This moment if user enter's correct username and password i just simply creating session:
At the moment I'm working with a git repo, locally so I don't to

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.