2012-12-08 91 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

相關問題