Android MySQL Tutorial to Perform Basic CRUD Operation

July 21, 2017 | Author: Maymay Pangilinan | Category: Sql, Php, Databases, Technology, World Wide Web
Share Embed Donate


Short Description

android...

Description

Android MySQL Tutorial to Perform Basic CRUD Operation Prerequisites – Android MySQL Tutorial  

Android Studio (Though you can do the same with eclipse) Wamp / Xamp Server (You can also use a live hosting server)

Creating the MySQL Database 

First create a database table.

Employee Table 



As you can see I have a table named employee with 4 columns (id, name, designation, salary). Id is set auto increment and primary key so we do not need to insert id. Now we will create our php scripts.

Creating PHP Scripts The first thing we need is to connect to the database. So create a file named dbConnect.php and write the following code. 1 2 3 4 5 6 7 8 9 1 0 1 1 1

5 8 9 1 1 1 4 1 5 1 6

Now write the following code in ViewAllEmployee.java 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36

package net.simplifiedcoding.mysqlcrud; import import import import import import import import import import import import import

android.app.ProgressDialog; android.content.Intent; android.os.AsyncTask; android.support.v7.app.AppCompatActivity; android.os.Bundle; android.view.Menu; android.view.MenuItem; android.view.View; android.widget.AdapterView; android.widget.ListAdapter; android.widget.ListView; android.widget.SimpleAdapter; android.widget.Toast;

import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import java.util.ArrayList; import java.util.HashMap; public class ViewAllEmployee extends AppCompatActivity implements ListView.OnItemClickListener { private ListView listView; private String JSON_STRING; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_view_all_employee); listView = (ListView) findViewById(R.id.listView); listView.setOnItemClickListener(this);

37 getJSON(); 38 } 39 40 41 private void showEmployee(){ 42 JSONObject jsonObject = null; 43 ArrayList list = new ArrayList(); 44 try { 45 jsonObject = new JSONObject(JSON_STRING); 46 JSONArray result = jsonObject.getJSONArray(Config.TAG_JSON_ARRAY); 47 48 for(int i = 0; i
View more...

Comments

Copyright ©2017 KUPDF Inc.
SUPPORT KUPDF