想要将数据从sqlite数据库传输到服务器
问题描述:
enter image description here我已经开发了一个离线数据录入应用程序在Android用户输入所有的细节将被保存在SQLite数据库。想要将数据从sqlite数据库传输到服务器
在一天结束时,我想将数据从sqlite数据库传输到一个存储PostgreSQL数据库中的数据的服务器。根据我的要求,我没有找到任何好的答案。
答
/// 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数据到服务器............其工作正常。 –
我没有看到任何问题。 – greenapps
究竟是什么问题?你不能从你的SQLite中读取数据?你不能发送数据到服务器? –
其实我必须从sqlite数据库发送整个数据到服务器 –