0

I created android application which use DataBase. So I have such a method which fills up the database.

private  void Add(String Name,String Descrition)
    {
        try
        {
            SQLiteDatabase db = this.getWritableDatabase();
            db.execSQL("Insert into Tablename (Name,Description) "
                    + "values ('" + Name + "' ,'" + Description "));


        }
        catch (Exception ex)
        {
        }
    }

When my application is running on the device for the first time, application fill up database by calling this method many times. My application use many a lot of data, so first launch of the application takes a long time. So I have one questions.

Is the possible create database file and next attach to application?? As a result, application would have to be filling up the database for the first time. How do it ??

  • Please note that normally, you should not use `try`/`catch`, and that an empty `catch` is even worse. – CL. Feb 13 '15 at 09:36

3 Answers3

0

Your application shouldn't be recreating a new database every time it is started. Once values have been inputted, it should stay in there unless you uninstall and reinstall the application.

If you want to make SQLite DB operations easier, check out http://developer.android.com/reference/android/database/sqlite/SQLiteOpenHelper.html

  • My application is not recreating a new database every time it is started. Application create database only one, when is running first time on device. But first launching application take a long time. Threrefore I want to generate database file and attach to application. – user3170606 Feb 12 '15 at 20:43
0

I am agree, your application shoudn't recreated the database.

Check this tutorial, may it helps : http://www.vogella.com/tutorials/AndroidSQLite/article.html

JavaJade
  • 199
  • 4
  • 13
0

You could use this: http://jgilfelt.github.io/android-sqlite-asset-helper/ ( https://github.com/jgilfelt/android-sqlite-asset-helper )

This class provides developers with a simple way to ship their Android app with an existing SQLite database (which may be pre-populated with data) and to manage its initial creation and any upgrades required with subsequent version releases.

Alexander Kulyakhtin
  • 47,782
  • 38
  • 107
  • 158