Create a SQLite database using SQLiteDatabase Browser, to include in your Android project

How to Create a SQLite database using SQLite Database Browser

1. If you don't already have an Android project, create an Android project.

2. Download and install SQLite Database Browser.

3. Create a new directory named assets in your Android app. Example: MyAppName\assets
The new database will need to be located here for Android to include it in your project.

4. Open the SQLite Database Browser software.


5. Click File - New Database.  Navigate to your App directory, then the assets folder. Type the name of your database you'd like to create and click the Save button. I will use the name mySQLiteDatabase here.



6. Another pop-up screen will display for you to enter a Table name. A database can contain many tables. I will call the table myTable1.



7. Now we will need to add our fields to the new Table called myTable1. Click the Add button below the Field name section. The first field that we need to create is the mandatory _id field. Add a field called _id and the select the Field Type of Integer Primary Key then click the Create button. (As I said, this field is mandatory. If it is not included, it will not work correctly in Android.)



8. Let's create another field named myField1 with the Field Type as Text  by clicking the Add button typing the information, and clicking the Create button


9. Click the Create button on the Create table window to create the table and field.



10. To add some test data, click the Browse data tab at the top. Then click the New Record button on the right.



11. A new record box will appear on the screen. Double-click the new box to add the new data. Type "This is a new record." Then click the Apply Changes button. (If you just click the Close button, your data will not be saved.)



12. For Android to recognize your new SQLite database, you will need to add a few more items. Click the Execute SQL tab. Copy the following line into the SQL string, and click the Execute query button.

CREATE TABLE "android_metadata" ("locale" TEXT DEFAULT 'en_US')


  1. 13. Under the Execute query button, the Error message from database engine: should display No error.
  2.  


    14. Now we need to add a single row to this new table. Copy the following line into the SQL string, and click the Execute query button.

    INSERT INTO "android_metadata" VALUES ('en_US')



  3. 15. Again, No error, should display under the Execute query button under the Error message from database engine.



16. You can now close the SQLite Database Browser software. Click yes to save any changes, if asked.

Next Recommended Article: How to Add an External SQLite database

Resources:
http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/



Web hosting