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.

Sign up to request clarification or add additional context in comments.

2 Comments

Yeah I tried to used ddms but when I click data folder it's empty
Accessing a SQLite database file via DDMS won't work on non-rooted devices. Best to use a SQL dump
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 Comments

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?
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.
Where is the connection string? Sorry for stupid questions but I am new to android
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;
0

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

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.