Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7718979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T03:18:01+00:00 2026-06-01T03:18:01+00:00

I am trying to upload values from an android sqlite3 database to a mysql

  • 0

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.

<?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->{'MobileID'}."', '".$obj->{'Latitude'}."', '".$obj->{'Longitude'}."', '".$obj->{'Speed'}."', '".$obj->{'Acceleration'}."', '".$obj->{'Time'}."', '".$obj->{'Date'}."', '".$obj->{'Sync'}."')");

?>

And here is the code snippet for posting the content from my sqlite3 database to the server.

        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();

The code snippet using HttpPost..

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 && 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;

}        

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T03:18:03+00:00Added an answer on June 1, 2026 at 3:18 am

    Is your auto-commit turned on?

    mysql_query('SET AUTOCOMMIT=1');
    

    If not, wrap your statements in

    mysql_query('START TRANSACTION');
    <your queries>
    mysql_query('COMMIT');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to upload a photo from android device to a php website. For
I'm trying to upload a file from Android (2.3.4) using the below code, I
i'm trying to upload some data from an ActiveX control to a webpage. The
I am trying to upload a file from a flash widget to my rails
i am trying to upload an image from a jsp page using servlet. but
I've been trying for some hours to grab the response from the imgur API.
I'm trying to upload an image to my server and the destination attribute of
im trying to use a file upload control from the obout control library, i
I am trying to upload files using Java URL class and I have found
I am trying to upload a text file of data to a soap server

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.