In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
The creation of Andorid Sqlite Database
To create a database, you will use an abstract class of SqliteOpenHelper. To create a database using this class, you must inherit the abstract class and use its methods.
The specific steps are as follows:
1. The custom class inherits SqliteOpenHelper
2. Add a constructor, in which the method of the parent class will be called to pass parameters. The name and meaning of the parameters are as follows
Public BookStoreDbOpenHelper (Context context) {
Super (context, "bookstore.db", null, 1)
/ * *
* parameters:
* 1 dint context context object
* 2 name the name of the database to be created
* 3 cursor factory, which is used to receive data
* 4 version number of the database to be created
, /
}
3, override the method of the parent class
Two important methods in the parent class, onCreate (SQLiteDatabase db) and onUpgrade (SQLiteDatabase db, int oldVersion, int newVersion)
The oncreate () method is called back when the database is created for the first time, which is suitable for initializing the table structure, that is, creating the required database tables.
OnUpdate () method: this method is called back when the database is updated, that is, when the version number changes, and is suitable for table operations in this method.
4, create a SqliteOpenHelper subclass object
/ / create a custom SqliteOpenHelper subclass to create the database
BookStoreDbOpenHelper helper = new BookStoreDbOpenHelper (mContext)
/ / call the parent method of this class to create the database
SQLiteDatabase db = helper.getReadableDatabase (); / / get a readable database object
The database is created and the database file exists in the data/data/ package name / databases directory
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.