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. INotificationService question


in fact the question relates to, but after looking into
the code it seems that INotificationService and its enqueueToast() may
steal toast's reference for a long time since when i run my Activity
several times wirhout Toast, Activity.getInstanceCount() returns
always 1 or 2, while when using Activity.getInstanceCount
() increments each time i run Activity and after long time is gc()'ed

so how can avoid that reference stealing?


2. Google Directions for maps!

Hi to everyone!!
So, I've to deliver a project in two week.In this project I should use
the package for drawing one the maps some Driving
or "Walking" DIRections but from some sites I have known that it isn't
avaible anymore for SDK 1.5(as it was for SDK 0.9).So please is there
anybody that can solve this problem??Is there an other way to obtain
that directions?



3. ListView addHeaderView gives ClassCastException when adding LinearLayout

4. InputMethodService and landscape mode

5. Calendar Widget is not there.. how to get it back?

6. Call log broken after 1.5 Cupcake update

7. Android Group on oDesk