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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:26:21+00:00 2026-05-25T16:26:21+00:00

I initially created an SQLite database on Windows and then had problems accessing it

  • 0

I initially created an SQLite database on Windows and then had problems accessing it within Android.

Subsequently I created a database on Android and then copied it out. At this point it only had the android_metadata table in it.

I then imported some data via CSV and added it back into my project. The DbHelper class in my project copies the database into /data/data/my.project/databases/.

Now, when I run a raw query from this database, if I try to access the table imported by CSV, I get an error saying that the table doesn’t exist. If I try to access the android_metadata table which I created on Android then there is no error.

The database in my assets definitely has the table in that I wish to copy over to the /data/data/example.project/databases folder and the copy routine is definitely called – I’ve checked with the log output.

Now, if I comment out the copy code, a database is automatically created which contains the android_metadata table in there and it is ~3 KB.

When the copy code is live the database is created as ~8 KB. This is the size of the database in the assets, so it appears that it has been successfully copied. However, when I pull that database back to my desktop from DDMS it is ~8 KB, but it doesn’t contain the table which is in the one in the assets folder. If I manually copy directly from desktop into /data/data… then the database works (but this will not be possible with a market app).

Here is my copy code for copying the database:

public void createDatabase() throws IOException {
    Log.i(TAG, "createDatabase called");

    InputStream assetsDB = mContext.getAssets().open(DATABASE_NAME);
    OutputStream dbOut = new FileOutputStream(DATABASE_PATH);

    Log.i(TAG, DATABASE_PATH);
    Log.i(TAG, assetsDB.toString());

    byte[] buffer = new byte[1024];
    int length;
    while ((length = assetsDB.read(buffer))>0) {
        Log.i(TAG, "WritingDB block" + length);
        dbOut.write(buffer, 0, length);
    }

    dbOut.flush();
    dbOut.close();
    assetsDB.close();
}

How can I fix this problem?

I’ve rectified this using another example which doesn’t override onCreate with the database copy code and handles the copying of the database on its own. I don’t really understand why it doesn’t work when calling the onCreate method.

  • 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-25T16:26:22+00:00Added an answer on May 25, 2026 at 4:26 pm

    Have you seen Using your own SQLite database in Android applications?

    This page is a good source for the topic. But, there is a little problem. Actually, it is not a problem and explained how to fix in the page. Look at comments.

    If your database is sort of largish or smallish (> 1 MB, < 100 KB (I am not sure about these values)). It seems that it is compressed and that causes confusion in the Android read on the InputStream. The trick is to rename your asset to a file that the packager will not try to compress. Renaming the database file from xxx to xxx.mp3 or xxx.txt or something like that does the trick.

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

Sidebar

Related Questions

When I initially create an SQLite database file with pre-inserted datasets for my application,
I initially designed my system following the s# architecture example outlined in this codeproject
Right, initially ran: c:\regsvr32 Amazing.dll then, (accidentally - I might add) I must have
I'm using SQLite in Windows from a .NET app. The .NET app is using
I need to migrate information that I created in SQLite3 to a MySQL database
How would I change the initial templates created by Xcode when creating a new
Java was initially slow before the JIT but today performance is pretty close to
I need to generate buttons initially based on quite a processor and disk intensive
I have a modal popup that initially shows some content but expands a div
Currently Tomcat's login support redirects users back to where they initially were when the

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.