Use of SQLite in Android

Source: Internet
Author: User

I learned a little about SQLite in Android through classroom exercises and surfing the Internet. Here we will share with you.

 

In Android development, SQLite can be operated in two ways. First, you can use/tools/sqlite3.exe In the Android SDK directory to perform database and table operations on the local hard disk. Assume that the SDK installation directory is C: \ Android_SDK (the operating system is windows ). Open the command line in windows, go to the C: \ Android_SDK \ tools \ directory, and run "sqlite3people. db ", a people will be created under the C: \ Android_SDK \ tools \ directory. db file, as shown in:



 

If only sqlite3 people. db is executed, the people. db file will not be created. You need to perform some actual operations after sqlite3people. db is executed. For example, tables.

 

This file is the file corresponding to the people database. We can use the sqlite command to perform various operations on the people database.

 

The other method is SQLite in the Android device of the Android simulator. Enable a simulator in AVD Manager and use the command line to locate the simulator in the C: \ Android_SDK \ platform-tools \ directory, run the adb shell command to enter the file system of the Android device. We can use sqlite3 to perform related operations on the SQLite database. Similar to Windows command lines, the sqlite3dbname command creates a dbname in the current directory. db file (if not, it is created and opened if it is available) to store the database content.

 

When we create a database using code in the Android project, because the path used by the program is data/PACKAGE_NAME by default, PACKAGE_NAME is the package name we specified when creating the android program. For example, we specified the package name ss. pku, there will be an ss under the data/path. pku directory. When creating a database in code, we specify the path of the database file, which is relative to the path of data/PACKAGE_NAME/databases. For example, according to the Code in the handout, If we specify DB_NAME as "people. db", a people. db file will be created under the data/PACKAGE_NAME/databases/directory. The data we operate on in the Code is stored in the database file. If you want to operate the database created in the code in shell, go to data/PACKAGE_NAME/database and execute sqlite3 people. db.





From Peking University-Google Android lab
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.