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. Null ptr exception before starting activity

Hi All,

I just deployed my first app on the market tonight. It was running
nice on the emulator and on my G2.
But apparently several users have difficulties starting the app, and I
can't figure out why.

Here is the crash dump:
java.lang.RuntimeException: Unable to start activity ComponentInfo
java.lang.reflect.Method.invokeNative(Native Method)
dalvik.system.NativeStart.main(Native Method)

Any ideas ?


2. Android Online Radio

Does anyone know where I can download this app? Apparently, this is
the developers' website:
I have been searching & searching for an online radio aside from
streamfurious. Thanks


3. feedback system

4. ListView addHeaderView gives ClassCastException when adding LinearLayout

5. How can I give my paid app away for free to some users?

6. mp3 streaming

7. Notification when the WIFI is ready to use