enter image description here我在android中开发了一个离线数据输入应用程序,用户输入将保存在sqlite db中的所有详细信息。
在一天结束时,我想将数据从sqlite数据库传输到服务器,该服务器将数据存储在PostgreSQL数据库中。根据我的要求,我没有找到任何好的答案。
答案 0 :(得分: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);
}