Android development: cmd cooperates with Android Device Monitor to open the sqlite database

SQLite is a lightweight relational database built into the android system. How to open and use it when we are learning is the focus of our study in this article. The so-called android pit is getting deeper and deeper, let us step into it step by step.

1. First of all, there is a built-in debugging tool adb in the Android SDK. In the adnroid sdk/platform-tools directory, if you want to use adb in cmd, you must first configure the system environment variables. I will not introduce how to configure it here. Simple.


2. After configuring adb, we can use adb. Before opening cmd, we first open Android Device Monitor, and then run the emulator (remember to open Android Device Monitor first , otherwise it will report device offline in adb shell).

In Android Device Monitor we can see the /data folder. At this time, it cannot be opened because of permissions. Next, we will use cmd to remove permissions for it.



3. First open cmd, first enter adb shell, su, and then cd.


After completion, you can open all the files under data.


4. Then, if you want to view the tables of our Sqlite database, you can cd to /data/data/com.databasetest/databases/, and use the ls command to view your database files. My database is called BookStore.db, and BookStore.db-journal is just a temporary file and can be ignored.


5. The next step is to view our database tables. Here we need to use the sqlite3 command, followed by our database name BookStore.db, enter the .table command after pressing Enter, and you can view the table we built; here we built two tables, Book and Category.


But it’s not over yet, we can use the select * from Book; ( note that there is a semicolon after it ) command to view the data under my Book table


Of course, you can also use the .schema command to view your table creation statement


6. When we need to import files, enter adb root in cmd and click the export button on the left.

. But before that, we must select our simulator name, otherwise the following situation will appear:


Well, the introduction of this article is almost done here. I hope it can help everyone. If you have anything to add, please leave a message.

Reminder: When adb cannot be used, please change to another emulator to test. For example, my Nexus 5X emulator will not work, I hope everyone will not fall into the trap!


Guess you like

Origin blog.csdn.net/HJ_CQ/article/details/78791301