How to view Android SQLLite database on emulator

荒凉一梦 提交于 2019-12-08 06:58:48

问题


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:-

  1. Download the jar file
  2. Add the jar file in your eclipse/dropins/ folder
  3. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!