1. Are you ready for the Galaxy S20? Here is everything we know so far!

Using an Emulator to update a table in MySQL

Discussion in 'Android Apps & Games' started by GraemeLeech, Feb 18, 2011.

  1. GraemeLeech

    GraemeLeech Lurker
    Thread Starter

    Hey folks, I have a problem trying to use an Android App I developed using Eclipse Helios to connect to a MySQL Database and run a PHP File through the emulator.

    The PHP File is working properly as when I run it through Internet Exlporer it updates the table in MySQL.

    Please find the code for my App below. The App actually worked once but since then it hasn't been working.

    package com.test.helloworld;

    import org.apache.http.client.HttpClient;
    import org.apache.http.client.methods.HttpPost;
    import org.apache.http.impl.client.DefaultHttpClient;
    import android.app.Activity;
    import android.widget.*;
    import android.os.Bundle;
    import android.util.Log;
    import android.view.*;

    public class HelloWorldApp extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    Button yes_button = (Button) findViewById(R.id.button);
    yes_button.setOnClickListener(new View.OnClickListener() {

    public void onClick(View v) {
    // Connect to Server and update the MY_TABLE DB;
    try
    {
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httpPost = new HttpPost("http://localhost:3128/YES_BUTTON.php");
    httpclient.execute(httpPost);
    }
    catch(Exception e)
    {
    Log.e("log_tag", "Error in updating MY_TABLE DB"+e.toString());
    }

    }
    });
    }
    }


    Any help would be appreciated, I think it might be an issue with the configuration files as the code seems to be ok. Im using Apache 2.2, PHP 5.3.5 on a Windows 7 machine.
     

    Advertisement

  2. idavis

    idavis Newbie

    I am guessing it's because you have the URL set to localhost:
    "http://localhost:3128/YES_BUTTON.php"

    Since this is coming from the phone, localhost would be the phone. I would change this to the actual location of the http server and it should work.
     
    GraemeLeech likes this.
  3. GraemeLeech

    GraemeLeech Lurker
    Thread Starter

    Hey thanks for replying to my post, I changed the 'localhost' to my IpAddress, and it still didn't work. I wonder if there is a setting I have to change to let the emulator use the internet to connect to my server and db. I have given it permission in the Manifest.xml file.
     
  4. idavis

    idavis Newbie

    When you changed the url, are you seeing a hit in the http server log from anything to that url? Is the ip address of your http server an internal ip (ie: 192.168.1.x)? If so, I am guessing the only way this will work is if you are connected through wifi to your router.

    If it's connecting through your phone provider you will have to make sure the ip is visible to the world. I would think that maybe airplane mode can ensure that it's only using the 802.11.
     
  5. GraemeLeech

    GraemeLeech Lurker
    Thread Starter

    I installed Apache on my laptop, I changed the url in the code to the IPv4 address of the laptop, dynamic address. I haven't installed the app yet on a phone, still testing it on the emulator. I checked the server log and the emulator never connected with it, and Im using a modem plugged into the laptop, I probably don't have it set up correctly at all!
     
Loading...
Similar Threads - Using Emulator update
  1. violetadelijevic1970
    Replies:
    1
    Views:
    115
  2. Android News
    Replies:
    0
    Views:
    26
  3. Android News
    Replies:
    0
    Views:
    8
  4. walterbyrd
    Replies:
    1
    Views:
    179
  5. willsp28
    Replies:
    13
    Views:
    454
  6. Flamster
    Replies:
    4
    Views:
    285
  7. Michtifus
    Replies:
    1
    Views:
    149
  8. Jeff Hood
    Replies:
    7
    Views:
    235
  9. Cyberdev
    Replies:
    2
    Views:
    402
  10. kfrajer
    Replies:
    0
    Views:
    178

Share This Page

Loading...