Initial database population from large data files, several problems

by Alistair. » Fri, 06 Mar 2009 17:37:38 GMT

Sponsored Links

You might find this article of interest. This is a technique to pre-
populate the database and bundle into the assets directory of your



Initial database population from large data files, several problems

by Jesse McGrew » Sat, 07 Mar 2009 10:53:25 GMT


Pre-populating it and building the database file into your app, as the
other response suggested, is probably the best way to do it.

However, if you decide to populate the database when your app is first
run, you might still be able to speed it up by wrapping the whole
process inside an SQLite transaction. Otherwise, it creates a separate
transaction for each query, which is slow. That's according to the
SQLite Optimization FAQ ( ~jplyon/sqlite/
SQLite_optimization_FAQ.html), although that FAQ is out of date by now
so maybe it's no longer true.



Sponsored Links

Initial database population from large data files, several problems

by Justin Allen Jaynes » Sat, 07 Mar 2009 16:49:02 GMT


This is precisely the approach I was looking for.  Thank you--most 
invaluable to me.



Initial database population from large data files, several problems

by Justin Allen Jaynes » Sun, 08 Mar 2009 11:09:58 GMT


I'm having a little trouble actually implementing the code from that
forum. It's an IOException I'm getting, and I've tracked it down to the
exact line in my code.

What I've done so far:

1. created the database file named wordlist.db and placed it in the
assets folder of my Eclipse Package Explorer Tree. (I'm certain this
database file is good--at least on my desktop machine--who knows what's
happening when it goes to the phone)
2. adapted the code to my purose.
3. after getting an IOException, I commented out all the lines of code
in the method copyDataBase, and then added them back in one at a time
until the exception was thrown again.
4. I simplified the code just to be sure and removed the while loop,
replacing it with:; but I still throw an error when
this line is not commented out.

Is there a way to see a more specific error than just IOException, and
if not, what might be a possible cause for being unable to read a byte
block from the file?

My code:

public void onCreate(SQLiteDatabase db) {
try {
} catch (IOException e) {
throw new Error("Error copying database " + e);

private void copyDataBase() throws IOException{

//Open your local db as the input stream
InputStream myInput = myContext.getAssets().open("wordlist.db");

// Path to the just created empty db
String outFileName = DATABASE_PATH + "wordlist.db";

//Open the empty db as the output stream
//OutputStream myOutput = new FileOutputStream(outFileName);

//transfer bytes from the inputfile to the outputfile
byte[] buffer = new byte[1024];
int length;
while ((length = > 0) {
// myOutput.write(buffer, 0, length);

//Close the streams


Alistair. wrote:


Initial database population from large data files, several problems

by pawpaw17 » Thu, 30 Apr 2009 01:24:06 GMT


I get the same exact error as you do. My thinking is it is because our
DB files are too
big. Have you made any progress on this?


Other Threads

1. Installed Application Version

This isnt stricktly a developer question, but once an app is installed
on the phone how can you tell what the version is that is in the
manifest file?


2. Progress bar for upload / doenload

I've been having some difficulties with  the progress bar. I built a
separate test harness and now I start to see things more clearly. The
code below seems to work correctly, but updates the progress bar only
when it finishes. I want it to update as the progress is made!

package com.example.progressbartest;
<snip imports>

public class ProgressBarTest extends Activity {
        static int i;
    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) {
        // Request the progress bar to be shown in the title

        final ProgressBar progressHorizontal = (ProgressBar)
        while (i<1000){
                Log.e("John","in loop"+Integer.toString(i));

There are actually two progress bars, like in the API demo app. One in
the title bar and another in the main screen. One would be sufficient,
but I don't know (yet) how to get rid of just one!


3. hardware interrupts

4. Load Html text and image in WebView (stored in files directory)

5. Crash in Dialer, Music on non-touchscreen device

6. how to make sound hz?

7. Help regarding large Database....