In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces the relevant knowledge of how to achieve database programming in Android, the content is detailed and easy to understand, the operation is simple and fast, and has a certain reference value. I believe you will gain something after reading this Android article on how to achieve database programming. Let's take a look at it.
The location of Android database storage is in data/data//databases/
1: create an Android database
Context.createDatabase (String name,int version, int mode,CursorFactory factory) throws a FileNotFoundException exception if the creation is not successful
Java code
SQLiteDatabase DataBase=this.openOrCreateDatabase ("DataBase.db", MODE_PRIVATE, new CursorFactory () {/ / create a new database with the name Database Pattern MODE_PRIVATE public Cursor newCursor (SQLiteDatabase db, SQLiteCursorDriver masterQuery, String editTable, SQLiteQuery query) {return null }}); SQLiteDatabase DataBase=this.openOrCreateDatabase ("DataBase.db", MODE_PRIVATE, new CursorFactory () {/ / create a new database with the name Database, schema MODE_PRIVATE public Cursor newCursor (SQLiteDatabase db, SQLiteCursorDriver masterQuery, String editTable, SQLiteQuery query) {return null;}})
2: open the existing database Context.openDatabase (String file,CursorFactory factory); if we want to open a database that does not exist, create it as follows:
Java code
/ / create a database named: DataBase with the suffix .db SQLiteDatabase DataBase=this.openOrCreateDatabase ("DateBase.db", MODE_PRIVATE, null) / / you can also write try {/ / Open the existing database db = this.openDatabase ("DateBase.db", null) } catch (FileNotFoundException e) {try {/ / create a new database} catch (FileNotFoundException e) {db = null }} / / create a database named: DataBase with the suffix .db SQLiteDatabase DataBase=this.openOrCreateDatabase ("DateBase.db", MODE_PRIVATE, null); / / you can also write try {/ / Open the existing database db = this.openDatabase ("DateBase.db", null) } catch (FileNotFoundException e) {try {/ / create a new database} catch (FileNotFoundException e) {db = null;}}
3: close the database
Java code
/ / Don't forget to close the database, oh DataBase.close (); / / never forget to close the database, oh, DataBase.close ()
4: delete the specified database
Java code
This.deleteDatabase ("Database.db"); this.deleteDatabase ("Database.db")
5: execute the SQL command using:
This is the end of the SQLiteDatabase.execSQL (String sql) article on "how to implement database programming in Android". Thank you for reading! I believe that everyone has a certain understanding of the knowledge of "how to realize database programming in Android". If you want to learn more knowledge, you are welcome to follow the industry information channel.
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.