Can I Import and export the SQLite database? means that I just want to carry the database. .DB
file will be put on my sd card. The app will fetch data from a database at sd card and write the data on that database. After using the app. close the app and take a .db
file to other devices and able to see the previous data and can manipulate that database.
Asked
Active
Viewed 313 times
0

Phantômaxx
- 37,901
- 21
- 84
- 115

vivek jha
- 9
- 3
-
Sqlite will not write to a database file on sd card. Only to a file in the internal private database directory. But you can copy that file to sd card and then take the card to a different device. It is unclear how you wanna take the file to another device. – greenapps Apr 12 '18 at 07:38
-
Given that you write code to access the same database in terms of tables and entities yes this can be done. – Murtaza Khursheed Hussain Apr 12 '18 at 07:42
-
I just want to use a button to browse the .db file from sd card. Then, copy that .db file to app SQLite database.After using that database and manipulating the data on the database at Android data folder and then export it. – vivek jha Apr 12 '18 at 07:44
-
Have a look at these answers https://stackoverflow.com/questions/33812960/how-to-store-chat-history-in-sqlite-at-runtime-like-whatsapp-in-android https://stackoverflow.com/questions/37785297/how-to-dynamically-create-sqlite-database-in-external-folder – Woods Apr 12 '18 at 07:45
-
Means, I am creating a database named "student.DB " with the help of DB browser.That DB will put into the external storage like a removable sd card. then, A button on the app will allow a user to browse that database from sd card. then, copy that database from sd card and use the app. when I will close the app database will be exported to the sd card. means I will enter the name of a student " Vivek". It can be seen in another device – vivek jha Apr 12 '18 at 07:55
-
Yes, you can. Just copy the database file from the app storage to the SD card and vice-versa. You can do that programmatically. – Phantômaxx Apr 12 '18 at 09:32
-
@KlingKlang Can you give me the reference for this? Thanks in advance. – vivek jha Apr 12 '18 at 10:45
-
You can mutuate the technique from [here](https://stackoverflow.com/questions/2409126/android-pre-populated-database?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa), for instance. – Phantômaxx Apr 12 '18 at 12:09
1 Answers
0
You can get database file in SD-Card with use of ORM. But not using default SQLiteOPenHelper.
Check Litepal Framework: For more info check this https://github.com/LitePalFramework/LitePal
Define where the .db file should be. "internal" means the .db file
will be stored in the database folder of internal storage which no
one can access. "external" means the .db file will be stored in the
path to the directory on the primary external storage device where
the application can place persistent files it owns which everyone
can access. "internal" will act as default.
For example:
<storage value="external" />

Nik
- 1,991
- 2
- 13
- 30