Url to connect android to mysql database-Collection of common programming errors
I am trying to retrieve data from localhost database created using xampp mysql.
public class JASONUseActivity extends Activity {
EditText byear; // To take birthyear as input from user
Button submit;
TextView tv; // TextView to show the result of MySQL query
String returnString; // to store the result of MySQL query after decoding JSON
/** Called when the activity is first created. */
@Override
protected void onCreate(Bundle savedInstanceState) {
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
.detectDiskReads().detectDiskWrites().detectNetwork() // StrictMode is most commonly used to catch accidental disk or network access on the application's main thread
.penaltyLog().build());
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
byear = (EditText) findViewById(R.id.editText1);
submit = (Button) findViewById(R.id.submitbutton);
tv = (TextView) findViewById(R.id.showresult);
// define the action when user clicks on submit button
submit.setOnClickListener(new View.OnClickListener(){
public void onClick(View v) {
// declare parameters that are passed to PHP script i.e. the name birth year and its value submitted by user
ArrayList postParameters = new ArrayList();
// define the parameter
postParameters.add(new BasicNameValuePair("birthyear",byear.getText().toString()));
String response = null;
// call executeHttpPost method passing necessary parameters
try {
response = CustomHttpClient.executeHttpPost("http://localhost/jasonscript.php",postParameters);
// store the result returned by PHP script that runs MySQL query
String result = response.toString();
I am not able to view data in textview. Is the url correct??
Here is the jasonscript.php located in xampp/htdocs