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

  • Home
  • SEARCH
  • 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 8503927
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:53:20+00:00 2026-06-11T01:53:20+00:00

SOLUTION I had to override the getReadableDatabase() and getWritableDatabase() in my custom DBHelper class.

  • 0

SOLUTION

I had to override the getReadableDatabase() and getWritableDatabase() in my custom DBHelper class.

I am facing a unique kind of problem.

Until now, I have written Android apps that have used one SQLite DB internally on the phone memory, and it works perfectly. Now I wanted to add another DB and wanted to store it on the SD card. I did this by modifying the DatabaseHelper class that we usually use. I have also written a script that transfers the db from the assets folder to the SD card for one DB and the internal memory location for another.

Now the problem that I am facing is that when I try to access the external DB, android creates an internal DB in the /data/data/package_name/databases folder and thus I end up getting no such table exception.

Can someone tell me why I am getting this error!


Edit 1
My DB Helper Class

public class DBHelper extends SQLiteOpenHelper {
private Context myContext;
private String DB_PATH;
private String DB_NAME;
private boolean isExternal;
private SQLiteDatabase myDataBase;

private final String TAG = "ERROR";

public DBHelper(Context AppC, String DB_NAME, boolean isExternal,
        int DB_VERSION) {
    super(AppC, DB_NAME + ".sqlite", null, DB_VERSION);
    this.myContext = AppC;
    this.isExternal = isExternal;
    this.DB_NAME = DB_NAME;
    setDbPath();
}

private void setDbPath() {
    if (this.isExternal) {
        try {
            DB_PATH = Environment.getExternalStorageDirectory()
                    + "/myappname/";
        } catch (Exception e) {
            DB_PATH = "/mnt/sdcard/myappname/";
        }
    } else {
        try {
            DB_PATH = Environment.getDataDirectory()
                    + "/data/my.app.package/databases/";
        } catch (Exception e) {
            DB_PATH = "data/data/my.app.package/databases/";
        }
    }
}

/**
 * Creates a empty database on the system and rewrites it with your own
 * database.
 * */
public void createDataBase() throws IOException {
    boolean dbExist = checkDataBase();
    if (!dbExist) {
        try {
            copyDataBase();
        } catch (Exception E) {
            // MRC
        }
    }
}

/**
 * Copies your database from your local assets-folder to the just created
 * empty database in the system folder, from where it can be accessed and
 * handled. This is done by transferring byte streams.
 * */
private void copyDataBase() throws IOException {
    String filePath = DB_PATH + this.DB_NAME + ".sqlite";

    if (this.isExternal) {
        File file = new File(filePath);
        if (!file.exists()) {
            File dir = new File(DB_PATH);
            if (dir.exists() || dir.mkdirs()) {
                transferFromAssets(this.DB_NAME + ".zip", filePath);
            } else {
                Log.d(TAG, "Unable to create dir " + DB_PATH);
            }
        }
    } else {
        // By calling this method and empty database will be created
        // into the default system path of your application so we
        // will be able to overwrite that database with our
        // database.

        SQLiteDatabase db_Read = this.getReadableDatabase();
        db_Read.close();
        transferFromAssets(this.DB_NAME + ".zip", filePath);
    }
}

private void transferFromAssets(String from, String to) throws IOException {
    ZipInputStream myInput = new ZipInputStream(myContext.getAssets().open(
            from));
    myInput.getNextEntry(); // Open the empty db as the output stream
    OutputStream myOutput = new FileOutputStream(to);
    // transfer bytes from the inputfile to the outputfile
    AndroidUtil.copyStream(myInput, myOutput);
}

/**
 * Check if the database already exist to avoid re-copying the file each
 * time you open the application.
 * 
 * @return true if it exists, false if it doesn't
 */
private boolean checkDataBase() {
    File dbFile = new File(DB_PATH + this.DB_NAME + ".sqlite");
    return dbFile.exists();
}

public void openDataBase() throws SQLException {
    String myPath = DB_PATH + this.DB_NAME + ".sqlite";
    Log.d(TAG, "Opening DB:" + myPath);
    myDataBase = SQLiteDatabase.openDatabase(myPath, null,
            SQLiteDatabase.OPEN_READWRITE);
}

@Override
public synchronized void close() {
    if (myDataBase != null)
        myDataBase.close();
    super.close();
}

public void onCreate(SQLiteDatabase db) {

}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

}

}

*My Internal Memory DB’s class’s constructor *

public WordsDB(Context AppC) {
    DBAPI = new DBHelper(AppC, "DB_NAME", false, 11);
    this.AppC = AppC;
    try {
        DBAPI.createDataBase();
        DBAPI.openDataBase();
    } catch (IOException e) {
        CustomToast.Toast(AppC, "", TCategory_E.CRITICAL_ERROR,
                TDuration_E.LONG, TPosition_E.CENTER);
        // MRC
    }
}

** My External DB class’s constructor **

public BackupDB(Context AppC) {
    DBAPI = new DBHelper(AppC, "/mnt/sdcard/myapp/backup-db",
            true, 11);
    this.AppC = AppC;
    try {
        DBAPI.createDataBase();
        DBAPI.openDataBase();
    } catch (IOException e) {
        CustomToast.Toast(AppC, "", TCategory_E.CRITICAL_ERROR,
                TDuration_E.LONG, TPosition_E.CENTER);
        // MRC
    }
}

Edit 2

The function in the external DB’s helper class that leads to the error:

public void setValue(int No, int Stars) {
    try {
        ContentValues update = new ContentValues();
        update.put(COL_STARRED, Stars);
        String args[] = { No + "" };
        SQLDB = DBAPI.getWritableDatabase();
        SQLDB.acquireReference();
        SQLDB.update(TABLE_NAME, update, COL_ID + "=?", args);
        SQLDB.releaseReference();
        SQLDB.close();
    } catch (Exception E) {
        Log.d(TAG, E.getMessage());
    }
}

If I try to use the external DB as an internal DB, there is no error which leads me to think that there is something wrong that I am doing for an external DB.

  • 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-11T01:53:21+00:00Added an answer on June 11, 2026 at 1:53 am

    Can you please provide some code?

    I did this by modifying the DatabaseHelper class that we usually use

    Can you please describe what modification did you made?
    If you are using SQLiteOpenHelper, be aware that DB path, that is passed to it’s constructor – is relative to /data/data/package/databases/ folder, so you cannot pass SD path there. If you will still need this – I’ll suggest using ContextWrapper and redefining it’s getDatabasePath method to point to your SD DB.

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

Sidebar

Related Questions

I have found some similar Que's on SO but had not find the solution.
I've tried to search for a solution for this, but have had no joy:
i have installed openipmp server on my windows. They had given some client solution
I've had this problem in a few different apps now and I can't seem
Solution: I had also moved ashx and asmx files at the same time as
Using visual studio 2008, I had a solution open and realized I need to
I had my VB.NET project and associated solution (developed in Visual Studio 2005) in
If i had two different application running under the same solution but using different
Has anyone else had this issue and found a working solution? I've enabled the
Looking for a non-JS solution. Say I had something like this: <ul> <li> <form>

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.