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?

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Radek
  • 1,403
  • 3
  • 25
  • 54

3 Answers3

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?

Tom Cerul
  • 1,773
  • 2
  • 13
  • 27
  • 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 03 '11 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 03 '11 at 15:30
  • Where is the connection string? Sorry for stupid questions but I am new to android – Radek Oct 03 '11 at 15:54
  • Sorry, I don't know Android yet. Someone over here is talking about connecting... http://stackoverflow.com/questions/5001124/how-to-connect-an-sqlite-database-sqlite-firefox-extension-to-android-applicat 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 03 '11 at 15:58
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.

Andras Balázs Lajtha
  • 2,576
  • 25
  • 32
0

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

Community
  • 1
  • 1
Robert Martin
  • 16,759
  • 15
  • 61
  • 87