如何在Double的类型中插入数据到phpmyadmin?

时间:2012-12-08 11:29:38

标签: java android eclipse phpmyadmin

我正在使用eclipse创建一个Android应用程序,它将读取用户输入的价格。

输入的价格应存储在数据库(phpmyadmin)

我正在使用下面的代码但是eclipse有错误并要求我将double转换为字符串。

            food = Double.parseDouble(inputFood.getText().toString());
            transport = Double.parseDouble(inputTransport.getText().toString());
            tele = Double.parseDouble(inputTele.getText().toString());
            academic = Double.parseDouble(inputAcademic.getText().toString());
            entertainment = Double.parseDouble(inputEntertainment.getText().toString());
            health = Double.parseDouble(inputHealth.getText().toString());
            others = Double.parseDouble(inputOthers.getText().toString());
            budget = Double.parseDouble(inputBudget.getText().toString());

            total = food + transport + tele + academic + entertainment + health + others;          
            balance = budget - total;

           List<NameValuePair> params = new ArrayList<NameValuePair>();
           params.add(new BasicNameValuePair("food", food));
           params.add(new BasicNameValuePair("transport", transport));
           params.add(new BasicNameValuePair("tele", tele));
           params.add(new BasicNameValuePair("academic", academic));
           params.add(new BasicNameValuePair("entertainment", entertainment));
           params.add(new BasicNameValuePair("health", health));
           params.add(new BasicNameValuePair("others", others));
           params.add(new BasicNameValuePair("budget", budget));
           params.add(new BasicNameValuePair("total", total));
           params.add(new BasicNameValuePair("balance", balance));

           JSONObject json = jsonParser.makeHttpRequest(url_save_expenses,
                               "GET", params);

是否有其他编码用于存储双数据?

感谢您的回答..

1 个答案:

答案 0 :(得分:2)

只需编写代码以此方式在列表中添加params

       params.add(new BasicNameValuePair("food", "" + food));
       params.add(new BasicNameValuePair("transport", "" + transport));
       params.add(new BasicNameValuePair("tele", "" + tele));
       params.add(new BasicNameValuePair("academic", "" + academic));
       params.add(new BasicNameValuePair("entertainment", "" + entertainment));
       params.add(new BasicNameValuePair("health", "" + health));
       params.add(new BasicNameValuePair("others", "" + others));
       params.add(new BasicNameValuePair("budget", "" + budget));
       params.add(new BasicNameValuePair("total", "" + total));
       params.add(new BasicNameValuePair("balance", "" + balance));

这会将此double类型更改为此Constuctor的字符串,并在服务器端将字符串转换为double并存储到数据库中