Is there a any way to submit data stored in an android SQLite database in format
-------------------------------------------- ID PRODUCT_ID AMOUNT -------------------------------------------- 1 001 4 2 008 5 3 006 2
to PHP web server using HTTP in android. I am maintaining a local database for specific transaction and after user complete the transaction I want to submit those data in to web system.Can anybody please help me regarding this.
Convert each row of the database into a JSONObject and store all the rows into a JSONArray
Convert the JSONArray into a json string using jsonArray.toString() and make an HTTP POST request. Make sure to set the Content-Type parameter to application/json
On the server side, process the request accordingly and store it into a database.
Note: If you’re having large amounts of data, it might be better to transfer the JSON Objects in batches. You can add parameters to the requests to denote batch ids when you reconstruct the database.
EDIT: I’m assuming you know how to fetch the cursor to the database.
You can use the following code
When you’re building the HTTP POST request, do
jArray.toString()to get a JSON string representing the array. Hope this helps.