SQLite database for Android Development
As shown in the preceding example, run the following command first:
When we click each button, the corresponding operation prompt will be output in the logcat log, as shown below:
The following describes the complete project development process.
1. Create an android project named SQLite.
2. Modify the layout file main. xml. The Code is as follows:
3. Here we create a database operation helper class sqliteopenhelper. java. This class can complete the creation, Open Database and various database operations. Here we can create a database and a table. The specific code is as follows:
4. Modify the activity code. Here we mainly perform some simple operations on the database. The Code is as follows:
5. after the project is completed, click execute to obtain the above results.
Here, I need to talk about it. If you want to see the database you created, you can use either of the following methods:
First, go to cmd to view the database. The specific steps are as follows:
(1) Run-> Enter cmd-> ADB shell, and then input ls, the following results will be displayed:
(2) run the CD command to enter the directory data. You need to repeat the operation twice here. After ls, there will be a lot of packages, of course, there are also projects you have created, due to the reason of the screen I only part of the screenshot. As follows:
(3) Find the package of your project, use CD to enter, and then ls, databases will appear, and then enter databases. Then ls will show the database you created. As follows:
(4) Go to the database and view the data in the created table and table. here we need to use sqlite3 for operations,
The procedure is as follows:
Second, check in file explorer in ddms of eclipse. The specific operations are as follows:
Go to data> DATA> Find the project package> enter the package> databases to find the created database.
Now, the entire database operation is complete. Thank you!