0

I have a dump database. I just wanted to insert the database into my application and retrive it. Please help me. I am new to android .. Thanks in advance.

3
  • Where your database is and where you want to copy ? Commented Sep 24, 2013 at 5:59
  • Please ask only full question with your code.. Commented Sep 24, 2013 at 6:01
  • I am doing a vocabulary application. It contains nearly 8000 records. So how can i insert into the android application and retrive it.. Is there any code or procedure for that ? Kindly help Commented Sep 24, 2013 at 6:03

3 Answers 3

2
void checkDB() throws Exception {
    try {
        SQLiteDatabase dbe = SQLiteDatabase
                .openDatabase(
                        "/data/data/yourpackagename/databases/yourfilename.sqlite",
                        null, 0);
        Log.d("opendb", "EXIST");
        dbe.close();
    } catch (Exception e) {

        AssetManager am = getApplicationContext().getAssets();
        OutputStream os = new FileOutputStream(
                "/data/data/yourpackagename/databases/yourfilename.sqlite");
        byte[] b = new byte[100];

        int r;
        InputStream is = am.open("yourfilename.sqlite");
        while ((r = is.read(b)) != -1) {
            os.write(b, 0, r);
        }
        Log.i("DATABASE_HELPER", "Copying the database ");
        is.close();
        os.close();
    }

}

Please Refer this link

Using your own SQLite database in Android applications

Sign up to request clarification or add additional context in comments.

1 Comment

OMG! I already tried with that link u provided but didn't changed the database Field id to "_id". Thanks a lot
1

I recommend this way. Create CSV file of your values. Insert it into the Assets folder.

Than on first run read file and insert it into the SQLite database on your phone.

I can post code examples later.

Good luck.

Comments

1

There's a library for that, I used it once, too.

https://github.com/jgilfelt/android-sqlite-asset-helper

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.