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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:49:59+00:00 2026-05-16T04:49:59+00:00

As the database in my app grows, it is going to require more and

  • 0

As the database in my app grows, it is going to require more and more of the internal phone space. There isn’t any sensitive/private data in the DB, so I’m interested in moving it to the SD card.

I’m using SQLiteOpenHelper to assist with the database work. It’s my understanding that you can’t use this for DB-access on the SD card as you can’t define the DB path. However, there are some (very poor) examples on the Internet that suggest you can override this limitation. However I’ve never gotten one of those code samples to compile.

Is it possible? And if so–HOW! Please note that Froyo’s “apps on SD card” feature won’t work as it doesn’t move internal files.

  • 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-16T04:50:00+00:00Added an answer on May 16, 2026 at 4:50 am

    Just use:

    SQLiteDatabase.openDatabase(DB_FULL_PATH, null, SQLiteDatabase.OPEN_READONLY);
    

    where DB_FULL_PATH can be a path to your sdcard, like /sdcard/mydatabase.db

    Edit:

    This is what I call in my application to access the database….

    private static DBUtil dbHelper = null;
    
    public void openDatabase() {
        if(dbHelper == null) {
            dbHelper = new DBUtil(this.context);
            dbHelper.openDataBase(SQLiteDatabase.OPEN_READWRITE);
        }
    }
    public void closeDatabase() {
        if(dbHelper != null) {
            dbHelper.close();
            dbHelper = null;
        }
    }
    

    … and this is the db helper class I’m using, which in fact extends SQLiteOpenHelper, so you will still have everything you want from this class.

    package com.myapp.android.db;
    
    import android.content.Context;
    import android.database.SQLException;
    import android.database.sqlite.SQLiteDatabase;
    import android.database.sqlite.SQLiteException;
    import android.database.sqlite.SQLiteOpenHelper;
    import android.util.Log;
    import com.myapp.android.MyApp;
    
    import java.io.IOException;
    
    /**
     * Standard database utility class.
     * 
     * TODO: Refactor.
     */
    public class DBUtil extends SQLiteOpenHelper {
    
        /**
         * Database directory.
         * 
         * <p>
         * Example: "/sdcard/myapp/db/"
         * </p>
         */
        public static String DB_DIRECTORY = null;
    
        /**
         * Name of the database file.
         * 
         * <p>
         * Example: "mydatabase.db"
         * </p>
         * 
         */
        public static String DB_NAME = null;
    
        /**
         * Full absolute path of the database.
         * 
         * <p>
         * Example: "/sdcard/myapp/db/mydatabase.db"
         * </p>
         */
        public static String DB_FULL_PATH = null;
        static {
            DB_DIRECTORY = MyApp.DATA_REPOSITORY_URI + "/myapp/db/";
            DB_NAME = "mydatabase.db";
            DB_FULL_PATH = DB_DIRECTORY + DB_NAME;
        }
    
        private SQLiteDatabase myDataBase;
    
        /**
         * Constructor Takes and keeps a reference of the passed context in order to
         * access to the application assets and resources.
         * 
         * @param context
         */
        public DBUtil(Context context) {
            super(context, DB_NAME, null, 1);
    
            try {
                this.createDataBase();
            } catch (IOException ioe) {
                throw new Error("Unable to create database");
            }
        }
    
        /**
         * Creates a empty database on the system and rewrites it with your own
         * database.
         * */
        public void createDataBase() throws IOException {        
            if (!checkDataBase()) this.getWritableDatabase();
        }
    
        /**
         * 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() {
            SQLiteDatabase checkDB = null;
            try {
                checkDB = SQLiteDatabase.openDatabase(DB_FULL_PATH, null,
                        SQLiteDatabase.OPEN_READONLY);
            } catch (SQLiteException e) {
                // database does't exist yet.
            }
            if (checkDB != null) {
                checkDB.close();
            }
            return checkDB != null ? true : false;
        }
    
        public void openDataBase(int mode) throws SQLException {        
            try {
                myDataBase = SQLiteDatabase.openDatabase(DB_FULL_PATH, null, mode);
            } catch(IllegalStateException e) {
                // Sometimes, esp. after application upgrade, the database will be non-closed, raising a IllegalStateException
                // below. Try to avoid by simply opening it again.
                Log.d(MyApp.APP, "Database non-closed. Reopening.");
                myDataBase = SQLiteDatabase.openDatabase(DB_FULL_PATH, null, mode);
            }
        }
    
        public void openDataBase() throws SQLException {
            openDataBase(SQLiteDatabase.OPEN_READWRITE);
        }
    
        public SQLiteDatabase getDb() {
            return myDataBase;
        }
    
        @Override
        public synchronized void close() {
            if (myDataBase != null)
                myDataBase.close();
            super.close();
        }
    
        @Override
        public void onCreate(SQLiteDatabase db) {
        }
    
        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need a simple app to edit database tables. Are there any code generators
I have a web-app-database 3 tier server setup. Web requests data from app, and
I am building an app that talks to an Access database via OleDB/Jet. There
Our app (already deployed) is using an Access/Jet database. The upcoming version of our
The app my colleagues and I maintain has an Oracle database at the back-end.
Which language for quick GUI app + sqlite database CRUD (2-4 tables). Java, Python?
I have a simple app that uses an SQL Express 2005 database. When the
I'm writing a php app to access a MySQL database, and on a tutorial,
I have an app that needs to check a database table every minute. The
In a certain app I must constantly query data that are likely to be

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.