2012-12-08 43 views
0

我使用eclipse来创建一个android应用程序,它将读取用户输入的价格。如何将数据以double类型插入到phpmyadmin中?

价格应输入storeed到数据库(phpMyAdmin的)

我使用下面的代码,但这次月食有错误,并要求我的双重转换为字符串。

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

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

谢谢回答..

回答

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

这将你的双类型更改为String此Constuctor,并在服务器端上的将字符串转换为加倍并存入数据库

+0

感谢您的回复。我的程序现在没有错误,但数据仍然无法存储到数据库中。最后是“不幸的是,系统已经停止” – user1850936

相关问题