In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
Most people do not understand the knowledge points of this article "how to use LitePal to operate the database in Android", so the editor summarizes the following contents, detailed contents, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "how to use LitePal to manipulate the database in Android" article.
First edit in the app/build.grade file
Dependencies {... conmpile'org.litepal.android:core:1.5'..}
Then create an assets directory and create a litepal.xml
Then add the code to the AndroidManifest.xml
Android:name= "org.litepal.litePalApplication"
To put it simply, the mode of object-relational mapping (ORM) in LitePal is to establish a mapping relationship between object-oriented language and object-oriented database, that is to say, you can use object-oriented thinking to operate the database instead of using the tedious steps of SQLiteOpenHelper.
Create an Abc class
Public class Abc extends DataSupport {private int id; private double price; private int pages; private String name; public int getId () {return id;} public void setId (int id) {this.id = id;} public int getPages () {return pages;} public void setPages (int pages) {this.pages = pages;} public String getName () {return name } public void setName (String name) {this.name = name;}}
Then add it to the litepal.xml
Then let's talk about the database upgrade mechanism of SQLiteOpenHelper. Each time it is executed, it will drop the database and then re-create it. While the drop database is also lost, you only need to modify what is needed to upgrade the database in LitePal, and then add the version number to one, that is,
All you need to add updated data is new an Abc and then call set
Public class MainActivity extends AppCompatActivity {@ Override protected void onCreate (Bundle savedInstanceState) {super.onCreate (savedInstanceState); setContentView (R.layout.activity_main); Button createDatabase = (Button) findViewById (R.id.create_database) CreateDatabase.setOnClickListener (new View.OnClickListener () {@ Override public void onClick (View v) {Abc abc=new Abc (); abc.setname ("litepal");}});}}
To delete data, use the
DataSupport.deleteAll (Abc.class, "name=?", "litepal")
Query data
List abc=DateSupport.findAll (Abc.class); the above is about "how to use LitePal to operate the database in Android". I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please pay attention to 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.