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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:39:25+00:00 2026-05-31T23:39:25+00:00

I’ve noticed in more than one SQLite tutorial that the table is recreated in

  • 0

I’ve noticed in more than one SQLite tutorial that the table is recreated in the onCreate() event of the class that extends SQLiteOpenHelper. I’ve already created my SQLite database and tables outside the Android environment (Eclipse IDE) with the help of a Firefox add-in. The database tables reside in the expected spot:

C:\aXX3&Space\Android\workspace\OnDemandAndAutomatic_Project\assets

It seems bizarre to me that I would have to recreate them programmatically each time (obviously, they continue to exist and retain data, or what would be the point)? However, I’m having a serious issue with this application right now which leads me to my question:

  • Is it really necessary reminding Android every time about the database?

Much to my chagrin, I just realized that instead of creating my database tables in C:\aXX3&Space\Android\workspace\OnDemandAndAutomatic_Project\assets, I had put them in C:\aXX3&Space\Android\workspace\OnDemandAndAutomatic\assets, which was an earlier version of the application, yet copying the SQLite file to the proper location didn’t change things a single bit. If this is what has been causing the problem, being that my application was looking for an AWOL database, is it not enough to simply copy and paste the file? Must I do something to officially
introduce the database to the system/Android/Eclipse directory? Any suggestions?

  • 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-31T23:39:26+00:00Added an answer on May 31, 2026 at 11:39 pm

    Actually SQLiteOpenHelper is responsible for your database creation, upgrade and many more.
    If you want to create tables programmatic then you have to write a create tables queries in the onCreate method of the SQLiteOpenHelper class.If you want to update your database after previously created database you can write the modified table’s queries in the onUpgrade method only you will have to change the database version.

    If you already created a database externally and if you want to use that database then you have to put that database in the assets folder and copy that file in the databases folder which is resides in the /data/data/packagename/databases folder.

    here is the example for copy database from assets to databases folder

    private static boolean copyDataBase(Context c) throws IOException {
        String DB_PATH = "/data/data/" + c.getPackageName() + "/databases/";
        AssetManager mg = c.getResources().getAssets();
        InputStream myInput = null;
    
        try {
            myInput = mg.open(DATABASE_NAME);
    
        } catch (IOException ex) {
            return false;
        }
    
        if (myInput != null) {
            String outFileName = DB_PATH + DATABASE_NAME;
            OutputStream myOutput = new FileOutputStream(outFileName);
            byte[] buffer = new byte[8000];
            int length;
    
            while ((length = myInput.read(buffer)) > 0) {
                myOutput.write(buffer, 0, length);
            }
            myOutput.flush();
            myOutput.close();
            myInput.close();
    
            Log.d(TAG, "Database is copied");
            return true;
        }
        return false;
    }
    

    Here is the method which check for the databases and its version for copy

    public void copyDatabase() {
    
        try {
            SharedPreferences preferences = c.getSharedPreferences(c.getPackageName(), Context.MODE_PRIVATE);
            if (checkDataBase(c)) {
                if (preferences.getInt("dbversion", 0) != 0) {
                    c.deleteDatabase(DatabaseHelper.DATABASE_NAME);
                }
    
            }
            getReadableDatabase();
            close();
            if (copyDataBase(c)) {
                Editor editor = preferences.edit();
                editor.putInt("dbversion", DatabaseHelper.DATABASE_VERSION);
                editor.commit();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    

    Here is the example which check whether the database is already exists or not?

    public static boolean checkDataBase(Context c) {
        File f = new File("/data/data/" + c.getPackageName() + "/databases/"
                + DATABASE_NAME);
        if (!f.exists())
            return false;
        SQLiteDatabase checkDB = null;
        try {
            checkDB = SQLiteDatabase
                    .openDatabase("/data/data/" + c.getPackageName()
                            + "/databases/" + DATABASE_NAME, null,
                            SQLiteDatabase.OPEN_READONLY);
            checkDB.close();
        } catch (SQLiteException e) {
            e.printStackTrace();
        }
        return checkDB != null ? true : false;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I am reading a book about Javascript and jQuery and using one of the
I have a French site that I want to parse, but am running into
In my XML file chapters tag has more chapter tag.i need to display chapters
I need a function that will clean a strings' special characters. I do NOT

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.