2

I have an Android application that creates a SQLite DB and populates it with some data.

How do I save this database to a file so it can be shipped with another application?

3 Answers 3

2

You can access the SQLite database file from the DDMS percpective of Eclipse when the device is connected, it is stored with your application's files in /data/data/package_name/databases.

There is a guide on how to find and replace a database by a preset file:

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

Or you can just create an SQL command dump, and make it execute on first launch is initialized - however it will be realy time consuming.

2
  • Yeah I tried to used ddms but when I click data folder it's empty
    – Radek
    Oct 3, 2011 at 15:57
  • Accessing a SQLite database file via DDMS won't work on non-rooted devices. Best to use a SQL dump
    – Kilizo
    Mar 22, 2013 at 22:59
2

sqlite saves its data directly to a file. It's already done. The filename is specified in your connection string.

Are you trying to export to a different file type for some other software to read in?

4
  • 1
    What I want is to have a pre populated db. So one app is run only once to read some data from a txt file and populate the db. Then I would put the db in assets folder of another app so it can read the data from there. So if it is saved to a file where is it saved so I can grab it a move somewhere else?
    – Radek
    Oct 3, 2011 at 15:26
  • Take a look in the connection string where you connect to the sqlite database. It should have something like "Data Source=" + filename. That's the filename of the database. Just copy that file.
    – Tom Cerul
    Oct 3, 2011 at 15:30
  • Where is the connection string? Sorry for stupid questions but I am new to android
    – Radek
    Oct 3, 2011 at 15:54
  • Sorry, I don't know Android yet. Someone over here is talking about connecting... stackoverflow.com/questions/5001124/… It looks this is the part with the database name. He's got it stored in a variable DB_NAME in his example. public DbManager(Context context) { super(context, DB_NAME, null, DB_VERSION); this.context = context;
    – Tom Cerul
    Oct 3, 2011 at 15:58
0

To export your SQLite data to a file, use the .dump command. See Exporting from SQLite to SQL Server

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.