Skip to content Skip to sidebar Skip to footer

How Can I Store My Arraylist Values To Mysql Databases?

I have some problem to store arraylist value to mysql database with php. This is some code I have been created. First, I have some class to store variable its called Constant.java

Solution 1:

Use HttpUrlConnection as Http Default client is no longer supported. Try this

 public JSONObjectfunction(String value_to_post, String  value_to_post,....){
        try {


            HashMap<String, String> params = newHashMap<>();

            params.put("your_database_field", value_to_post);



            Log.d("request", "starting");

            JSONObject json = jsonParser.makeHttpRequest(
                    your_URL, "POST", params);

            if (json != null) {
                Log.d("JSON result", json.toString());

                return json;
            }

        } catch (Exception e) {
            e.printStackTrace();
        }

        returnnull;
    }

call this function from your activity

Solution 2:

$_POST variable will hold your posted data.

Solution 3:

//You have to something similar. //This is just an idean as i dont know how you declared temp and arraylist

for (int i = 0; i < type.length; i++) {

             nameValuePairs.add(new BasicNameValuePair(list.get(i).getkey,list.get(i).getValue));

        }

Solution 4:

In Android:

postParameters.add(new Pair<>("value1", value1.toString()));

In Php

$str = str_replace(array('[',']'),'',$_POST['value1']);
$str = preg_replace('/\s+/', '', $str);
$value1 = preg_split("/[,]+/", $str);
$i=0;
while($i<count($value1){
$query = "insert into order(value1) values(value1)";
}

Solution 5:

You can use List<NameValuePair> to send POST request to server.

try {
        // Add your data
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
        nameValuePairs.add(new BasicNameValuePair("param1", "data1"));
        nameValuePairs.add(new BasicNameValuePair("param2", "data2"));
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

        HttpResponse response = httpclient.execute(httppost);

    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
    } catch (IOException e) {
        // TODO Auto-generated catch block
    }

Post a Comment for "How Can I Store My Arraylist Values To Mysql Databases?"