A SQLite database is just a file. You can take that file, move it around, and even copy it to another system (for example, from your phone to your workstation), and it will work fine. Android stores the file in the /data/data/packagename/databases/ directory. You can use the adb command or the File Explorer view in Eclipse (Window > Show View > Other... > Android > File Explorer) to view, move, or delete it.
Tutorial : How to access a Android database by using a command line.
When your start dealing with a database in your program, it is really
important and useful to be able to access it directly, outside your
program, to check what the program has just done, and to debug.
And it is important also on Android.
Here is how to do that :
1) Launch the emulator (or connect your real device to your PC ). I
usually launch one of my program from Eclipse for this. 2) Launch a
command prompt in the android tools directory. 3) type adb shell. This
will launch an unix shell on your emulator / connected device. 4) go
to the directory where your database is : cd data/data here you have
the list of all the applications on your device Go in your application
directory ( beware, Unix is case sensitive !! ) cd
com.alocaly.LetterGame and descend in your databases directory : cd
databases Here you can find all your databases. In my case, there is
only one ( now ) : SCORE_DB 5) Launch sqlite on the database you want
to check / change : sqlite3 SCORE_DB From here, you can check what
tables are present : .tables 6) enter any SQL instruction you want :
select * from Score;
This is quite simple, but every time I need it, I don't know where to
find it.
You can also check whether your IDE has a utility like Eclipse's DDMS perspective which allows you to browse through the directory and/or copy files to and from the Emulator or a rooted device.
This is and old question, but answering may help others.
Default path where Android saves databases can not be accesed on non-rooted devices. So, the easiest way to access to database file (only for debugging environments) is to modify the constructor of the class:
public class MySQLiteOpenHelper extends SQLiteOpenHelper {
MySQLiteOpenHelper(Context context) {
super(context, "/mnt/sdcard/database_name.db", null, 0);
}
}
Remember to change for production environments with these lines:
public class MySQLiteOpenHelper extends SQLiteOpenHelper {
MySQLiteOpenHelper(Context context) {
super(context, "database_name.db", null, 0);
}
}
If your application creates a database, this database is by default saved in the directory DATA/data/APP_NAME/databases/FILENAME.
The parts of the above directory are constructed based on the following rules. DATA is the path which the Environment.getDataDirectory() method returns. APP_NAME is your application name. FILENAME is the name you specify in your application code for the database.
If you name your db as a file without giving a path then most common way to get its folder is like:
final File dbFile = new File(getFilesDir().getParent()+"/databases/"+DBAdapter.DATABASE_NAME);
where DBAdapter.DATABASE_NAME is just a String like "mydatabase.db". Context.getFilesDir() returns path for app's files like: /data/data/<your.app.packagename>/files/ thats why you need to .getParent()+"/databases/", to remove "files" and add "databases" instead.
BTW Eclipse will warn you about hardcoded "data/data/" string but not in this case.
The Context contains many path functions: Context.getXXXPath()
One of them is android.content.Context.getDatabasePath(String dbname) that returns the absolute path of a database called dbname.
Context ctx = this; // for Activity, or Service. Otherwise simply get the context.
String dbname = "mydb.db";
Path dbpath = ctx.getDatabasePath(dbname);
The returned path, in this case, would be something like:
/data/data/com.me.myapp/databases/mydb.db
Note that this path is autogenerated if using SQLiteOpenHelper to open the DB.
Do not hardcode path like //data/data/<Your-Application-Package-Name>/databases/<your-database-name>. Well it does work in most cases, but this one is not working in devices where device can support multiple users. The path can be like //data/user/10/<Your-Application-Package-Name>/databases/<your-database-name>. Possible solution to this is using context.getDatabasePath(<your-database-name>).