2017-08-30 228 views
-4

enter image description here我已經開發了一個離線數據錄入應用程序在Android用戶輸入所有的細節將被保存在SQLite數據庫。想要將數據從sqlite數據庫傳輸到服務器

在一天結束時,我想將數據從sqlite數據庫傳輸到一個存儲PostgreSQL數據庫中的數據的服務器。根據我的要求,我沒有找到任何好的答案。

+1

我沒有看到任何問題。 – greenapps

+0

究竟是什麼問題?你不能從你的SQLite中讀取數據?你不能發送數據到服務器? –

+0

其實我必須從sqlite數據庫發送整個數據到服務器 –

回答

0
/// whrite this in database class 
    public Cursor getAllData(String emailid) { 
      String query = "select * from "+ORDERHISTORY_TABLE+" Where "+ ACCOUNT + "= '"+ emailid +"' ORDER BY "+ NOTIFICATION_RID +" ASC "; 
      SQLiteDatabase db = this.getReadableDatabase(); 
      Cursor cursor = db.rawQuery(query, null); 
      return cursor; 
     } 
////write this in java class 
        { 
    Cursor cursor = helpher.getAllData(Emailid);//cursor hold all your data 
        arr = new JSONArray(); 
        if (cursor.moveToFirst()){ 
         do { 
          jobj = new JSONObject(); 
          try { 
           jobj.put("Order_id", cursor.getString(1)); 
           jobj.put("Order_tittle", cursor.getString(2)); 
           jobj.put("Order_quantity", cursor.getString(3)); 
           jobj.put("Order_price", cursor.getString(5)); 
           jobj.put("Order_totalprice", cursor.getString(4)); 
           jobj.put("Order_image", cursor.getString(6)); 
           jobj.put("Address1", cursor.getString(8)); 
           jobj.put("Address2", cursor.getString(9)); 
           jobj.put("Name", cursor.getString(10)); 
           jobj.put("Phone", cursor.getString(11)); 
          } catch (JSONException e) { 
           e.printStackTrace(); 
          } 
          arr.put(jobj); 
         }while (cursor.moveToNext()); 
        } 
        jobj = new JSONObject(); 
        try { 
         jobj.put("data", arr); 
        } catch (JSONException e) { 
         e.printStackTrace(); 
        } 
        String st = jobj.toString(); 
       Log.i("jhfg",""+st); 




        try { 
         JsonObjectRequest request_json = new JsonObjectRequest("url", new JSONObject(st), 
           new Response.Listener<JSONObject>() { 
            @Override 
            public void onResponse(JSONObject response) { 
             //Process os success response 
            } 
           }, new Response.ErrorListener() { 
          @Override 
          public void onErrorResponse(VolleyError error) { 
           VolleyLog.e("Error: ", error.getMessage()); 
          } 
         }); 
        } catch (JSONException e) { 
         e.printStackTrace(); 
        } 

    // add the request object to the queue to be executed 
    //    ApplicationController.getInstance().addToRequestQueue(request_json); 

      } 
+0

通過上面的代碼,我們可以發送sqlite數據到服務器............其工作正常。 –

相關問題