{"id":6433,"date":"2014-04-18T05:22:11","date_gmt":"2014-04-18T05:22:11","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/04\/18\/url-to-connect-android-to-mysql-database-collection-of-common-programming-errors\/"},"modified":"2014-04-18T05:22:11","modified_gmt":"2014-04-18T05:22:11","slug":"url-to-connect-android-to-mysql-database-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/04\/18\/url-to-connect-android-to-mysql-database-collection-of-common-programming-errors\/","title":{"rendered":"Url to connect android to mysql database-Collection of common programming errors"},"content":{"rendered":"<p>I am trying to retrieve data from localhost database created using xampp mysql.<\/p>\n<pre><code>public class JASONUseActivity extends Activity {\n\n EditText byear;   \/\/ To take birthyear as input from user\n Button submit;    \n TextView tv;      \/\/ TextView to show the result of MySQL query \n\n String returnString;   \/\/ to store the result of MySQL query after decoding JSON\n\n    \/** Called when the activity is first created. *\/\n@Override\nprotected void onCreate(Bundle savedInstanceState) {\n    StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()\n      .detectDiskReads().detectDiskWrites().detectNetwork() \/\/ StrictMode is most commonly used to catch accidental disk or network access on the application's main thread\n      .penaltyLog().build());\n    super.onCreate(savedInstanceState);\n    setContentView(R.layout.main);\n    byear = (EditText) findViewById(R.id.editText1);\n    submit = (Button) findViewById(R.id.submitbutton);\n    tv = (TextView) findViewById(R.id.showresult);\n\n    \/\/ define the action when user clicks on submit button\n    submit.setOnClickListener(new View.OnClickListener(){        \n     public void onClick(View v) {\n\n         \/\/ declare parameters that are passed to PHP script i.e. the name birth year and its value submitted by user   \n      ArrayList postParameters = new ArrayList();\n\n      \/\/ define the parameter\n      postParameters.add(new BasicNameValuePair(\"birthyear\",byear.getText().toString()));\n      String response = null;\n\n      \/\/ call executeHttpPost method passing necessary parameters \n      try {\n response = CustomHttpClient.executeHttpPost(\"http:\/\/localhost\/jasonscript.php\",postParameters);\n\n \/\/ store the result returned by PHP script that runs MySQL query\n String result = response.toString();  \n<\/code><\/pre>\n<p>I am not able to view data in textview. Is the url correct??<\/p>\n<p>Here is the jasonscript.php located in xampp\/htdocs<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-6433","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/6433","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=6433"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/6433\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=6433"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=6433"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=6433"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}