0

I am developing an android application where I am fetch all the data in j son array. Now i want to send said Json array to MySQL database on server.

db.open();     
ArrayList<HashMap<String, String>> arrayList = db.Record();    
Gson gson = new Gson();   
String jsonPesan = gson.toJson(arrayList);  
db.close();
Hein
  • 2,675
  • 22
  • 32
Qamar Din
  • 21
  • 4
  • Try this tutorial, http://www.androidhive.info/2012/05/how-to-connect-android-with-php-mysql/ – Hein Feb 08 '16 at 06:48

2 Answers2

0

You need to make web-service ,you can post your data to server using webservice.

How to send data to MySQL DB without using JDBC , PHP or any other webservice?

Community
  • 1
  • 1
Vasant
  • 3,475
  • 3
  • 19
  • 33
0

You can use JSON API to create a json array and then use URL Builder to send the json as a parameter to the API.

jsonAttriArray = new JSONArray();
                                try {
                                    if (!someInput.getText().toString().equalsIgnoreCase(""))
                                             {
                                        JSONObject jsonObject1 = new JSONObject();
                                        jsonObject1.put("object1", someInput.getText());

                                        jsonAttriArray.put(jsonObject1);
                                    }
                                    if (!someInput2.getText().toString().equalsIgnoreCase(""))
                                             {
                                        JSONObject jsonObject2 = new JSONObject();
                                        jsonObject2.put("object2", someInput2.getText());

                                        jsonAttriArray.put(jsonObject2);

                                    }

                                } catch (Exception e) {
                                    // TO DO
                                }

Uri.Builder builder = new Uri.Builder(); builder.appendQueryParameter("jsonparams", jsonAttriArray.toString());

 String query = builder.build().getEncodedQuery();
            OutputStream os = conn.getOutputStream();
            BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, "UTF-8"));
            writer.write(query);
            writer.flush();
            writer.close();
            os.close();
Aziz
  • 234
  • 1
  • 5
  • db.open(); ArrayList> arrayList = db.Record(); Gson gson = new Gson(); String jsonPesan = gson.toJson(arrayList); db.close(); You already have the code just start a loop and insert the arrayList values in the Json array like what I did in above code and then you have the json String with you. You try first and then it it doesn't work we can look into it – Aziz Feb 08 '16 at 10:17
  • Dear how to connect server and that this j son array to server database MySQL please help me – Qamar Din Feb 08 '16 at 10:36
  • Dear Aziz reply please – Qamar Din Feb 08 '16 at 10:37
  • Hein provided you with a tutorial link, please follow that and do everything step by step – Aziz Feb 08 '16 at 10:38
  • dear this tutorials bit difficult for me pleas help me tell me step to connect with server and post data in MySQL database – Qamar Din Feb 08 '16 at 10:42