-2

How would you make a java code for an image like this?

That is from an Android emulator. I'm trying to input post data information into each slot and upload the information to a MySQL database.

This is the code so far:

public class Registration extends Activity {

    TextView Taccount,Tpassword,Tfirst,Tlast,Temail,Tlocation,Tdescription;
    EditText Eaccount,Epassword,Efirst,Elast,Eemail,Elocation,Edescription;
    Button btnCreate;
    String page="";
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_cappuccino);
        btnCreate = (Button) findViewById(R.id.btnGen);
        Taccount = (TextView) findViewById(R.id.txtAccountID);
        Eaccount = (EditText) findViewById(R.id.editAccountID);
        Tpassword = (TextView) findViewById(R.id.txtPassword);
        Epassword = (EditText) findViewById(R.id.editPassword);
        Tfirst = (TextView) findViewById(R.id.txtFirst);
        Efirst = (EditText) findViewById(R.id.editFirst);
        Tlast = (TextView) findViewById(R.id.txtLast);
        Elast = (EditText) findViewById(R.id.editLast);
        Temail = (TextView) findViewById(R.id.txtEmail);
        Eemail = (EditText) findViewById(R.id.editEmail);
        Tlocation = (TextView) findViewById(R.id.txtLocation);
        Elocation = (EditText) findViewById(R.id.editLocation);
        Tdescription = (TextView) findViewById(R.id.txtDescription);
        Edescription = (EditText) findViewById(R.id.editDescription);

        btnCreate.setOnClickListener(new Button.OnClickListener()
        {
            public void onClick(View v)
            {
                examineJSONFile();
            }
        });
    }
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_cappuccino, menu);
        return true;
    }

    void examineJSONFile()
    {
        try
        {
            JSONObject object=new JSONObject();
            object.put("Account ID", Eaccount.getText());
            object.put("Password", Epassword.getText());
            object.put("First Name", Efirst.getText());
            object.put("Last Name", Elast.getText());
            object.put("Email", Eemail.getText());
            object.put("Location", Elocation.getText());
            object.put("Description", Edescription.getText());
            String str=object.toString();
            executeHttpPost(str);
            Log.i("JsonString :", str);
            Toast.makeText(this, "Json Objects are : " + str,Toast.LENGTH_LONG).show();


        }
        catch (Exception je)
        {

        }
    }

    public  void executeHttpPost(String string) throws Exception 
    {
        //This method  for HttpConnection  
        try 
        {
            HttpClient client = new DefaultHttpClient();

            HttpPost request = new HttpPost("http://localhost:8080/example/database/Cappuccino.sql");

            List<NameValuePair> value=new ArrayList<NameValuePair>();

            value.add(new BasicNameValuePair("Account ID",string));

            UrlEncodedFormEntity entity=new UrlEncodedFormEntity(value);

            request.setEntity(entity);

            client.execute(request);

           System.out.println("after sending :"+request.toString());

        } 
     catch(Exception e)     {System.out.println("Exp="+e);
        }

    }


}

Thanks in advance!

tenorsax
  • 21,123
  • 9
  • 60
  • 107
Ed Lee
  • 387
  • 2
  • 7
  • 12
  • So...What exactly are you asking? What have you tried? what research have you done? What is not working? – 0gravity Aug 11 '12 at 04:50
  • Hi, Ed. In order to get useful assistance it's usually better to provide a specific question or set of questions, the work that you've already performed to answer them, and a description of your roadblocks. If you're having trouble getting started try working through some of the Android development tutorials. http://developer.android.com/training/index.html – Carth Aug 11 '12 at 04:53

2 Answers2

0

One way to accomplish this through is using Webservice. You have to create webservice to access MySQL database. It can be created using php, jsp, etc.

We pass the values to webservice using internet connection.

webservice processes this data and gives back the response.

http://www.codeproject.com/Articles/112381/Step-by-Step-Method-to-Access-Webservice-from-Andr

This link can help you to learn how to do this..

Rahmathullah M
  • 2,676
  • 2
  • 27
  • 44
0

There are a variety of ways that you could do this.

One approach (probably the simplest) would be to use JDBC and a suitable JDBC driver to access the database directly from your Android app; e.g. as described in this question Using SQL (JDBC) database in Android. (This assumes that you understand how to use SQL and JDBC ... but these are standard technologies, and you need to understand them if you are going to do anything serious using a MySQL database from Java.)

Another approach would be to create some kind of wrapper service for the database, but this seems unnecessarily complicated to me if you just want to upload data without any additional validation or processing.

Community
  • 1
  • 1
Stephen C
  • 698,415
  • 94
  • 811
  • 1,216