In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-10-20 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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.