read/send data from MySQL via PHP webservice

What is JSON

  • JSON stands for JavaScript Object Notation
  • JSON is lightweight text-data interchange format
  • JSON is language independent
  • JSON is “self-describing” and easy to understand
    (from w3schools)

1. a PHP web service which encodes a string array in to JSON format:  access that web service using Android http client and then it decodes json data


$data = array('name' => 'Froyo', 'version' => 'Android 2.2');
print (json_encode($data));
Android activity:

HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("");
TextView textView = (TextView)findViewById(;
try {
HttpResponse response = httpclient.execute(httppost);
String jsonResult = inputStreamToString(response.getEntity().getContent()).toString();
JSONObject object = new JSONObject(jsonResult);
String name = object.getString("name");
String verion = object.getString("version");
textView.setText(name + " - " + verion);
catch (JSONException e) {
catch (ClientProtocolException e) {
catch (IOException e) {

2. A Web service to read data from the MySQL database

Java web service deployed on Tomcat server has a method which can run a quarry on database to retrieve data & this method returns results as a string output. To connect web service & database JDBC bridge will be used. The Android application calls that web service method remotely using ksoap library. Then web service runs a query on database table to retrieve data & returns data as a string to Android app. Android app display this data.

import ksoap2 library into project!!

Insert data to a database.

private final String NAMESPACE = "";

    private final String SOAP_ACTION = "";
    private final String METHOD_NAME = "insertData";

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s




Just another site

Jing's Blog

Just another site

Start from here......







Just another site

Where On Earth Is Waldo?

A Project By Melanie Coles

the Serious Computer Vision Blog

A blog about computer vision and serious stuff

Cauthy's Blog

paper review...

Cornell Computer Vision Seminar Blog

Blog for CS 7670 - Special Topics in Computer Vision


Life through nerd-colored glasses

Luciana Haill

Brainwaves Augmenting Consciousness



Dr Paul Tennent

and the university of nottingham

turn off the lights, please

A bunch of random, thinned and stateless thoughts around the Web

%d bloggers like this: