I have created a SQLite file and putted it on to assets folder. Now I am able to read the data from that file but I don't have any idea how to write to this database file. I need to take the user name and score and store that in to that database file. I searched on the web and on the SO also but there are examples for the normal database insertion.
Can any one tell me how to store the values into database file. I need to store the username and score. Just think this to as Strings and please give me a example for it.
you need to copy database file from asset and paste in /data/data/''/databases/ folder
In Above code : Replace [PACKAGE NAME ] with your package name I hope above code will help.
Thank You
You should not create database in the assets folder as we can only read data from assets folder.
Infact you should create the database in the default internal folder i.e data/data/[package-name]/databases OR you also can create your database in the sdcard and can perform read-write operation but of course it will not run if there is no sdcard.
The following is the code for creating databse in sdcard:-
As the
/asset
directory is read only (because android .apk file is read-only) so you can't write anything in asset folder file, you have to first copy that sqlite database file into your application's internal storage/data/data/<package_name>/databases
directory then you can modify your database file..Copy your pre-populated sqlite database file into
data/data/<package_name>/databases directory
,Open that database file (from /databases/ directory) in your sqlite database helper class..
Perform insert, update or select operation on that database..