0

The database structure will be as follows:

city_id     city_name
   1        Hyderabad
   2        pune
   5        mumbai......

I want to add the data to my app's database from the .db file which is in the assets folder of the project.

Reeno
  • 5,720
  • 11
  • 37
  • 50
Amaresh Jana
  • 732
  • 11
  • 22
  • Actually I wanna add that kind of data to my database...becoz I need to show that data in the login to select there city and send the city of along with the username and password to the server.... – Amaresh Jana Sep 17 '15 at 06:40
  • 1
    Have you tried this? http://stackoverflow.com/questions/17142081/android-external-database-in-assets-folder – hoomi Sep 17 '15 at 06:41
  • Yea....that's good and I have a txt with json string how can I use that....to insert the data from that txt file can v do that... – Amaresh Jana Sep 17 '15 at 06:46
  • 1
    Can you not convert the txt file into .db file in your computer and then put the db file in the asset folder. It improves the performance of your app when you want to create the database. – hoomi Sep 17 '15 at 06:49
  • Yea...thx for the solution... – Amaresh Jana Sep 17 '15 at 06:54
  • No problem should I add that as an answer? – hoomi Sep 17 '15 at 06:57
  • Yea...u can do that for sure...... – Amaresh Jana Sep 17 '15 at 06:59

2 Answers2

1

There is a good answer in here Android external database in assets folder.

Just to improve the performance of your app, I would suggest that you make the db file in your computer and then import the .db file in the assets folder. (not the .txt file directly)

Community
  • 1
  • 1
hoomi
  • 1,882
  • 2
  • 16
  • 17
0
ContentValues values = new ContentValues();
for(int i = 0; i<=5; i++) {
    values.put(city_id, cityId[i]);
    values.put(city_name, cityName[i]);
    db.insert(TABLE_NAME, null, values);
}
Nooruddin Lakhani
  • 7,507
  • 2
  • 19
  • 39