Note that there are some explanatory texts on larger screens.

plurals
  1. POPost values from android sqlite3 to sql database to have Sync operation
    primarykey
    data
    text
    <p>I am trying to upload values from an android sqlite3 database to a mysql database on my server. I have been successful in posting values from a single JSON object that I create. However, when I'm trying to sync values from my sqlite3 database, mysql database on server is not getting updated. Here is my php code on the server. </p> <pre><code>&lt;?php mysql_connect('localhost','sapeksha_me','getmein'); $json = file_get_contents('php://input'); $obj = json_decode($json); mysql_select_db("sapeksha_locationdata"); mysql_query("INSERT INTO location (MobileID, Latitude, Longitude, Speed, Acceleration, Time, Date, Sync) VALUES ('".$obj-&gt;{'MobileID'}."', '".$obj-&gt;{'Latitude'}."', '".$obj-&gt;{'Longitude'}."', '".$obj-&gt;{'Speed'}."', '".$obj-&gt;{'Acceleration'}."', '".$obj-&gt;{'Time'}."', '".$obj-&gt;{'Date'}."', '".$obj-&gt;{'Sync'}."')"); ?&gt; </code></pre> <p>And here is the code snippet for posting the content from my sqlite3 database to the server.</p> <pre><code> SQLiteDatabase db = databasehelper.getWritableDatabase(); Cursor cursor = db.query(TABLE, null, null, null, null, null, null, null); cursor.moveToFirst(); while(cursor.isAfterLast() == false) { if(cursor.getString(cursor.getColumnIndex("Sync")).equals("yes") ) { String mob = cursor.getString(cursor.getColumnIndex("MobileID")); String lat = cursor.getString(cursor.getColumnIndex("Latitude")); String lng = cursor.getString(cursor.getColumnIndex("Longitude")); String speed = cursor.getString(cursor.getColumnIndex("Speed")); String acc = cursor.getString(cursor.getColumnIndex("Acceleration")); String date = cursor.getString(cursor.getColumnIndex("Date")); String time = cursor.getString(cursor.getColumnIndex("Time")); String update = cursor.getString(cursor.getColumnIndex("Sync")); JSONObject json = new JSONObject(); try { json.put("MobileID", mob); json.put("Latitude", lat); json.put("Longitude", lng); json.put("Speed", speed); json.put("Acceleration", acc); json.put("Time", time); json.put("Date", date); json.put("Sync", update); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { receive = HttpPostExample.SendJsonUpdate(json, Sync_URL); } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } Toast.makeText(context, receive, Toast.LENGTH_SHORT).show(); } cursor.moveToNext(); } cursor.close(); </code></pre> <p>The code snippet using HttpPost..</p> <pre><code>public static String SendJsonUpdate(JSONObject json, String URL) throws ClientProtocolException, IOException { try { HttpParams params = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(params, TIMEOUT_MILLISEC); HttpConnectionParams.setSoTimeout(params, TIMEOUT_MILLISEC); HttpClient client = new DefaultHttpClient(params); HttpPost post = new HttpPost(URL); post.setEntity(new ByteArrayEntity(json.toString().getBytes("UTF8"))); post.setHeader("json", json.toString()); StringEntity se; se = new StringEntity(json.toString()); post.setEntity(se); post.setHeader("Accept", "application/json"); post.setHeader("Content-type", "application/json"); post.setHeader("Accept-Encoding", "gzip"); long t = System.currentTimeMillis(); HttpResponse response = (HttpResponse) client.execute(post); Log.i(TAG, "HTTPResponse received in [" + (System.currentTimeMillis()-t) + "ms]"); HttpEntity entity = response.getEntity(); if(entity != null) { InputStream instream = entity.getContent(); Header contentEncoding = response.getFirstHeader("Content-Encoding"); if (contentEncoding != null &amp;&amp; contentEncoding.getValue().equalsIgnoreCase("gzip")) { instream = new GZIPInputStream(instream); } String resultString = convertStreamToString(instream); instream.close(); Log.i("Read from server", resultString); return resultString; } } catch (Exception e) { e.printStackTrace(); } return null; } </code></pre> <p>Logcat is showing the "HttpResponse received in []" statements, yet the database on the server is not getting updated. I have not still gained experience in android development and php/sql coding. The code might not be the best way of doing it but what am I doing wrong?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload