Thursday, March 16, 2017

How to use SQL in android app

Shared Preferences we usually use for data persistence Android. But the more complex the data or the data for the persistence  SharedPreferences is not a good option. So we have to use file storage or database. As the open source SQLite database system, which is built on Android. This database offline. This device contains a file store.Four database operation is the Create, Read, Update, Delete short CRUD. Simple create an app in which we will learn about the four operations.





We'll create a class. That all of us will manage the operation of the SQLite. I like the name Database Helper. Then we will have to Extend SQLiteHelper class. Extend SQLiteHelper abasayai and our two methods to implement, and onUpgrade One method onCreate.

It will take us two things to create a database, the name and version of the database. Just enough for us to create a database.



SQL Database android
S

When you create an instance of the file DatabaseHelper MainActiviy.java for us to create a database.


  

The database was created, we want to see it from Android Studio Tools> Android> Android Device Monitor will click. Here we have conn
ected the device or virtual device, the data show. From here Data> Data> app id, navigate to the folder name when Database. This folder will show Database. We want to be able to export the database computer. Database to pull to device by clicking on the icon that showed the location of the computer will be able to see.



Database What's in, what we want to see that the software can use the SQLite Database Browser. There are many extensions and Chrome browser or Firefox.He has Database Creator, then we'll database with data. To keep the data in our database table to create. A primary key must be on the table. That would be unique. For example, we'll create a database called friends. Friends_table will be the name of a table. There will be three rows in the table. ID, Friends Name & Friends Email. And for that we need to enter the following SQL query.











You can insert it in Dynamic:


 When you run this part of the table for us to create our database. If the table has been created, we can see the Device Monitor Exports from the database. If the data in the database so far everything we can. For some of the fields will add to our activity_main.xml file. Friend Name of a text field, Friend Email to a text field and a button. You can add your own wishes. This will add a reference to the MainActivity.java.Insert data to database information we need two. We will insert a data table, and it will insert the data. And it is providing us with a certain rules. Through Content Values. The data are to be kept in pairs.To insert data in the database, we DatabaseHelper insertData class will add a new method. The works, which will. Like the following: the



Then we edit the text file data from MainActiviy.java DatabaseHelper of the class method updateData'll pass. If you would like to have that ID data, we update, it will be updated.
 




2 comments:

  1. This comment has been removed by a blog administrator.

    ReplyDelete
  2. Great blog you have got here.. It’s hard to find excellent writing like yours these days.
    Android App Developer Sydney

    ReplyDelete