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();
1

2 Answers 2

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?

Sign up to request clarification or add additional context in comments.

Comments

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();

5 Comments

db.open(); ArrayList<HashMap<String, String>> 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
Dear how to connect server and that this j son array to server database MySQL please help me
Dear Aziz reply please
Hein provided you with a tutorial link, please follow that and do everything step by step
dear this tutorials bit difficult for me pleas help me tell me step to connect with server and post data in MySQL database

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.