The correct wording for Android build database

Source: Internet
Author: User

Create a new class called Xxxcontract, and in the class inside the static inner class inherits Basecolumn, writes the table name and the table column name in the inner class, because the Basecolumns class encapsulates a _id and _count, So the ID doesn't need to be defined by ourselves. The following code shows:

public class Personcontract {public    static class person implements basecolumns{public        static final String Table_ Name= "Person";        public static final String columns_name= "NAME";        public static final String columns_number= "number";    }}

Replace the data in the SQL statement with the data from the new class in the OnCreate method that inherits the Sqliteopenhelper class

Db.execsql ("CREATE TABLE" + personcontract.person.table_name+                "(" +personcontract.person._id                + "integer Primary key AutoIncrement, "+                personcontract.person.columns_name+" varchar (+), "+                personcontract.person.columns_number+ "varchar" + "                )";

The original code is the following, if you want to change it will be very cumbersome and error

Db.execsql ("CREATE TABLE Person" (_id integer primary key autoincrement,name varchar(), number varchar) ");

The correct wording for Android build database

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.