0

I have a SQLite database that I already created and it has data in it.

Now I just want to attach the database with existing tables and keys without any changes to the Android application and use it.

Most of the samples about SQLite databases in Android involve creating the database in the application, like this link. But my database file already exists.

After some searching, I found this link about database attachment but it isn't clear and I don't understand where I should put the database file and how to call the attachment query for it.

Community
  • 1
  • 1
Saman Gholami
  • 3,416
  • 7
  • 30
  • 71

2 Answers2

1

Just use sqllite asset helper

It's the best lib out there that serves your purpouse. I also wrote a blogpost about preloading sqllite data (and other stuff) here

fedepaol
  • 6,834
  • 3
  • 27
  • 34
0
String path = "/path/to/database/file";
SQLiteDatabase database = SQLiteDatabase.openDatabase(path, null, 0);
bhowden
  • 669
  • 7
  • 15