SQLite database used by Android

Source: Internet
Author: User
Tags line editor

SQLite allows you to ignore the data type. However, we recommend that you specify the data type in the create table statement, because the data type facilitates program readability. SQLite supports common data types, such as varchar, nvarchar, text, integer, float, Boolean, clob, blob, timestamp, numeric, varying, character, natl0nai, and varyingcharacter.

 

 

 

The Android device will be released with an internalSQLite Database. The purpose of this database is to allow users and developers to store information at activities.

If you have usedMicrosoft SQL ServerOr SQLite, the structure and process of the SQLite database using andorid will not be unfamiliar to you. Regardless of your experience, this section covers all the skills required to create and use a full-featured SQLite database. You will create a database on the android simulator. To achieve this, you needGo to the android SDK Command Line Editor ToolRun the shell command to access the android server.

Prompt

Refer to Chapter 3 to regain your memoryAbout path description and use command line tool.

Once you enter the server, you need to navigate to the database location. All Android SQLite databases are stored in data/<package>/
Databases directory. Use the CD command to change from the current directory to the data directory and then to the <package> directory. If you are not sure about the name of the <package> directory, use ls to list files and the current directory. Change the directory to <package> android_programmers _
Guide. findafriend, as shown below (omitted)

Warning

If you do not have the android_programmers_guide.findafriend directory, create your application as described in the previous section and run "Hello World !" The default application created by the project will ensure that you have a correct directory.

Find the android_programmers_guide.findafriend directory and run the is command. This command lists all the files and directories in a specific folder. The command should return empty content. Because there are no files or folders in this directory.

Assume that the SQLite database must be in a database directory under the local directory. It is time to create one.Mkdir tool creates a directory for you. Therefore, run the mkdir databases command. It will create a directory for retaining the database.

Warning

Now, you are almost in the root directory of the server. Therefore, the directory you just created will be entered as the root directory. When you run an activity, a problem may occur because each activity has a different user. To solve this problem for the purpose of development,Run chmod 777 DatabasesTo allow everyone to access the database directory. In the future, you must be very cautious about giving everyone the power to some sensitive Android entries. Only give specific users the right to use specific items.

You have created a database directory. You can create a database.Use the CD command to navigate to the database directory. After the database directory,Use sqlite3 to create a databaseAnd name it friends. dB as follows:

# SQLite friends. DB

If the command is successfully executed, you should see a sqlite3 version. In this example, It is 3.5.0 and a sqlite3 prompt-SQLite>. This indicates that the database has been created but is empty. The database does not contain tables and data. Remember, the next step is to create a table for the activity data.

Create a table named friends. This table retains the ID, name, location, created, and modified fields. These fields provide sufficient information for your project.

Prompt

If you are not familiar with SQLite,An SQLite command must end with a semicolon. This is helpful if you want to span a command. If the SQLite command is not terminated, press enter to continue giving you a prompt...>. You cannot enter the command at the prompt unless you use a semicolon. Once a semicolon is used, SQLite uses continuous commands as a complete command.

To create a friends table in the database, enter the following command at the SQLite> prompt:

Create Table friends (_ id integer primary key, Name text, location text,
Created integer, modified integer );

 

If the command is successfully executed, the SQLite> prompt is returned, as shown in (omitted ).

The database can now be used. You can exit SQLite.Use. Exit to exit. Then, you can exit the shell part and return it to eclipse.

Creating a database is the first step in creating an application. Now the database and the corresponding table have been created. You need a method to store the data. Android data is stored inContent Provider. How can I introduce the following content to you?Create a custom content provider for the new databaseAnd store data.

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.