问题
I've looked at answers to previous questions on this topic, but can't seem to get any of them to work. I am developing in Eclipse, and running the app on an emulator.
It seems like the simplest approach is to use the adb
shell in conjunction with the sqlite3 command. With adb I can see the emulator device. When I start the adb shell, I see a directory which is where I would expect to find the database:
/data/data/com.example.myfirstapp/databases/ (where com.example.myfirstapp is the package name of the app)
However, there are no .db
files in that directory. There is a file with the same name as the database the app created, but it does not have the .db
extension.
(I'm pretty sure I am seeing the file system of the emulated device because it does have the directory for my application).
UPDATE
After going through all the responses, and accessing the database via adb/sqlite3 and also using DDMD/Sqlite browser, I realized I made a "newbie" mistake in the code:
public class MessageOpenHelper extends SQLiteOpenHelper {
public static final String DATABASE_NAME = "MyFirstApp.db";
public static final String MESSAGE_COLUMN = "message";
public static final String MESSAGE_TABLE_NAME = "messages";
private static final String MESSAGE_TABLE_CREATE = String.format("create table %s (%s TEXT);", MESSAGE_TABLE_NAME, MESSAGE_COLUMN);
public MessageOpenHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
By convention, the database name should include the .db
extension. Although it works fine without it, the Sqlite browser for Eclipse won't recognize the file. Hopefully other neophytes like me won't make the same mistake.
回答1:
You mentioned you are using Eclipse ... You can go in DDMS perspective, select the db file and view in Sqllite Browser .. as shown below...
EDIT:- Forgot to mentioned we require to add the plugin here...
Follow the link here
Steps:-
- Download the jar file
- Add the jar file in your eclipse/dropins/ folder
- Restart Eclipse.. you will notice the icon in DDMS perspective..
回答2:
Yes, what 'David N' told true, but don't forget to click on device which is located at top left corner Devices tab before checking data -> data -> package name -> database name

回答3:
In eclipse, you can use the DDMS tab to view SQLite database.
Go to file explorer -> data -> data -> package name -> database name
You can now push or pull the database...
Hope it helps
来源:https://stackoverflow.com/questions/19521530/how-to-view-android-sqllite-database-on-emulator