{"id":16611,"date":"2022-10-20T21:58:54","date_gmt":"2022-10-20T16:28:54","guid":{"rendered":"https:\/\/jassweb.com\/solved\/solved-android-app-fetching-data-from-database-closed\/"},"modified":"2022-10-20T21:58:54","modified_gmt":"2022-10-20T16:28:54","slug":"solved-android-app-fetching-data-from-database-closed","status":"publish","type":"post","link":"https:\/\/jassweb.com\/solved\/solved-android-app-fetching-data-from-database-closed\/","title":{"rendered":"[Solved] Android app . fetching data from database [closed]"},"content":{"rendered":"<p> [ad_1]<br \/>\n<\/p>\n<div id=\"answer-40100200\" class=\"answer js-answer accepted-answer js-accepted-answer\" data-answerid=\"40100200\" data-parentid=\"40100040\" data-score=\"2\" data-position-on-page=\"1\" data-highest-scored=\"1\" data-question-has-accepted-highest-score=\"1\" itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n<div class=\"post-layout\">\n<div class=\"votecell post-layout--left\"><\/div>\n<div class=\"answercell post-layout--right\">\n<div class=\"s-prose js-post-body\" itemprop=\"text\">\n<p>If you wanna use the database as centralized then it should be a server but not Local DB.<br \/>\nLocal db can be accessible within the device as we all know and the below can help you to handle the server.<\/p>\n<p><strong>Step 1:<\/strong> First buy a server in either GoDaddy or 000webhost.com(Free server will be available)<\/p>\n<p><strong>step 2:<\/strong> Create a database and make some tables which matches your requirement.<\/p>\n<p><strong>step 3:<\/strong> Remaining all coding and integrating part is in this Url<br \/>\n<a rel=\"nofollow noopener\" target=\"_blank\" href=\"http:\/\/www.androidhive.info\/2012\/05\/how-to-connect-android-with-php-mysql\/\">Android Php connect<\/a><\/p>\n<p>This is the basic API for the starters, keep going.<\/p>\n<p>Android API integration using Java servlet<\/p>\n<p><strong>Step 1:<\/strong> Download Eclipse EE(Express Edition) or Add Eclipse EE plugin to your Existing Eclipse<\/p>\n<p><strong>Step 2:<\/strong> In your Eclipse go to File &gt; New &gt; Project &gt; Web &gt; Dynamic Web Project &gt; next. <\/p>\n<p><strong>Step 3:<\/strong> Name your Project and select Apache Tomcat v7.0 as the target runtime and click finish. <\/p>\n<p><strong>Step 4:<\/strong> Now right click on project &gt; New &gt; Other &gt; Web &gt; Servelt. Name the Servlet as your wish.<\/p>\n<p><strong>Step 5:<\/strong> As an Example I placed here two multiply the number with 2<\/p>\n<pre><code>import java.io.IOException;\nimport java.io.OutputStreamWriter;\n\nimport javax.servlet.ServletException;\nimport javax.servlet.ServletInputStream;\nimport javax.servlet.annotation.WebServlet;\nimport javax.servlet.http.HttpServlet;\nimport javax.servlet.http.HttpServletRequest;\nimport javax.servlet.http.HttpServletResponse;\n\n@WebServlet(\"\/DoubleMeServlet\")\npublic class DoubleMeServlet extends HttpServlet {\n    private static final long serialVersionUID = 1L;\n\n    public DoubleMeServlet() {\n        super();\n\n    }\n\n    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {\n\n        response.getOutputStream().println(\"Hurray !! This Servlet Works\");\n\n    }\n\n    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {\n\n        try {\n            int length = request.getContentLength();\n            byte[] input = new byte[length];\n            ServletInputStream sin = request.getInputStream();\n            int c, count = 0 ;\n            while ((c = sin.read(input, count, input.length-count)) != -1) {\n                count +=c;\n            }\n            sin.close();\n\n            String recievedString = new String(input);\n            response.setStatus(HttpServletResponse.SC_OK);\n            OutputStreamWriter writer = new OutputStreamWriter(response.getOutputStream());\n\n            Integer doubledValue = Integer.parseInt(recievedString) * 2;\n\n            writer.write(doubledValue.toString());\n            writer.flush();\n            writer.close();\n\n\n\n        } catch (IOException e) {\n            try{\n                response.setStatus(HttpServletResponse.SC_BAD_REQUEST);\n                response.getWriter().print(e.getMessage());\n                response.getWriter().close();\n            } catch (IOException ioe) {\n            }\n        }   \n        }\n\n}\n<\/code><\/pre>\n<p><strong>Step 6:<\/strong>  Right click on Servlet project &gt; Run as &gt; Run on Server. Run on Server Dialog should pop up. Select &#8220;Manually define a new server&#8221; and also Tomcat v7.0 under server type.&#8221; Before that make sure your tomcat server is up and running. Open your web browser and type <a rel=\"nofollow noopener\" target=\"_blank\" href=\"http:\/\/localhost:8080\">http:\/\/localhost:8080<\/a>. You should see a default page displayed by tomcat server. <\/p>\n<p>And below is the sample code, you should call your servlet file from your android app like this mentioned way<\/p>\n<pre><code>package com.app.myapp;\n\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\nimport java.net.URL;\nimport java.net.URLConnection;\nimport android.app.Activity;\nimport android.os.Bundle;\nimport android.util.Log;\nimport android.view.View;\nimport android.view.View.OnClickListener;\nimport android.widget.Button;\nimport android.widget.EditText;\n\npublic class DoubleMeActivity extends Activity implements OnClickListener {\n\n    EditText inputValue=null;\n    Integer doubledValue =0;\n    Button doubleMe;\n\n    @Override\n    public void onCreate(Bundle savedInstanceState) {\n        super.onCreate(savedInstanceState);\n        setContentView(R.layout.calculate);\n\n        inputValue = (EditText) findViewById(R.id.inputNum);\n        doubleMe = (Button) findViewById(R.id.doubleme);\n\n        doubleMe.setOnClickListener(this);\n    }\n\n    @Override\n    public void onClick(View v) {\n\n        switch (v.getId()){\n        case R.id.doubleme:\n\n              new Thread(new Runnable() {\n                    public void run() {\n\n                        try{\n                            URL url = new URL(\"http:\/\/10.0.2.2:8080\/MyServletProject\/DoubleMeServlet\");\n                            URLConnection connection = url.openConnection();\n\n                            String inputString = inputValue.getText().toString();\n                            \/\/inputString = URLEncoder.encode(inputString, \"UTF-8\");\n\n                            Log.d(\"inputString\", inputString);\n\n                            connection.setDoOutput(true);\n                            OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream());\n                            out.write(inputString);\n                            out.close();\n\n                            BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));\n\n                            String returnString=\"\";\n                            doubledValue =0;\n\n                            while ((returnString = in.readLine()) != null) \n                            {\n                                doubledValue= Integer.parseInt(returnString);\n                            }\n                            in.close();\n\n\n                            runOnUiThread(new Runnable() {\n                                 public void run() {\n                                  inputValue.setText(doubledValue.toString());\n\n                                }\n                            });\n\n                            }catch(Exception e)\n                            {\n                                Log.d(\"Exception\",e.toString());\n                            }\n\n                    }\n                  }).start();\n\n            break;\n            }\n        } \n    }\n<\/code><\/pre>\n<p>Refer the below link for complete reference<br \/>\n<a rel=\"nofollow noopener\" target=\"_blank\" href=\"http:\/\/www.veereshr.com\/Android\/AndroidToServlet\">Connect android app with servlet<\/a><\/p>\n<\/p><\/div>\n<div class=\"mt24\"><\/div>\n<\/div>\n<p>            <span class=\"d-none\" itemprop=\"commentCount\">2<\/span> <\/p><\/div>\n<\/div>\n<p>[ad_2]<\/p>\n<p>solved Android app . fetching data from database [closed] <\/p>\n","protected":false},"excerpt":{"rendered":"<p>[ad_1] If you wanna use the database as centralized then it should be a server but not Local DB. Local db can be accessible within the device as we all know and the below can help you to handle the server. Step 1: First buy a server in either GoDaddy or 000webhost.com(Free server will be &#8230; <a title=\"[Solved] Android app . fetching data from database [closed]\" class=\"read-more\" href=\"https:\/\/jassweb.com\/solved\/solved-android-app-fetching-data-from-database-closed\/\" aria-label=\"More on [Solved] Android app . fetching data from database [closed]\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[320],"tags":[452],"class_list":["post-16611","post","type-post","status-publish","format-standard","hentry","category-solved","tag-android"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>[Solved] Android app . fetching data from database [closed] - JassWeb<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/jassweb.com\/solved\/solved-android-app-fetching-data-from-database-closed\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"[Solved] Android app . fetching data from database [closed] - JassWeb\" \/>\n<meta property=\"og:description\" content=\"[ad_1] If you wanna use the database as centralized then it should be a server but not Local DB. Local db can be accessible within the device as we all know and the below can help you to handle the server. Step 1: First buy a server in either GoDaddy or 000webhost.com(Free server will be ... Read more\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jassweb.com\/solved\/solved-android-app-fetching-data-from-database-closed\/\" \/>\n<meta property=\"og:site_name\" content=\"JassWeb\" \/>\n<meta property=\"article:published_time\" content=\"2022-10-20T16:28:54+00:00\" \/>\n<meta name=\"author\" content=\"Kirat\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Kirat\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-android-app-fetching-data-from-database-closed\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-android-app-fetching-data-from-database-closed\/\"},\"author\":{\"name\":\"Kirat\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\"},\"headline\":\"[Solved] Android app . fetching data from database [closed]\",\"datePublished\":\"2022-10-20T16:28:54+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-android-app-fetching-data-from-database-closed\/\"},\"wordCount\":292,\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"keywords\":[\"android\"],\"articleSection\":[\"Solved\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-android-app-fetching-data-from-database-closed\/\",\"url\":\"https:\/\/jassweb.com\/solved\/solved-android-app-fetching-data-from-database-closed\/\",\"name\":\"[Solved] Android app . fetching data from database [closed] - JassWeb\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#website\"},\"datePublished\":\"2022-10-20T16:28:54+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-android-app-fetching-data-from-database-closed\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/jassweb.com\/solved\/solved-android-app-fetching-data-from-database-closed\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-android-app-fetching-data-from-database-closed\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/jassweb.com\/solved\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"[Solved] Android app . fetching data from database [closed]\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/jassweb.com\/solved\/#website\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"name\":\"JassWeb\",\"description\":\"Build High-quality Websites\",\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/jassweb.com\/solved\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\",\"name\":\"Jass Web\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"contentUrl\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"width\":693,\"height\":132,\"caption\":\"Jass Web\"},\"image\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\",\"name\":\"Kirat\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1776403586\",\"contentUrl\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1776403586\",\"caption\":\"Kirat\"},\"sameAs\":[\"http:\/\/jassweb.com\"],\"url\":\"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"[Solved] Android app . fetching data from database [closed] - JassWeb","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/jassweb.com\/solved\/solved-android-app-fetching-data-from-database-closed\/","og_locale":"en_US","og_type":"article","og_title":"[Solved] Android app . fetching data from database [closed] - JassWeb","og_description":"[ad_1] If you wanna use the database as centralized then it should be a server but not Local DB. Local db can be accessible within the device as we all know and the below can help you to handle the server. Step 1: First buy a server in either GoDaddy or 000webhost.com(Free server will be ... Read more","og_url":"https:\/\/jassweb.com\/solved\/solved-android-app-fetching-data-from-database-closed\/","og_site_name":"JassWeb","article_published_time":"2022-10-20T16:28:54+00:00","author":"Kirat","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Kirat","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jassweb.com\/solved\/solved-android-app-fetching-data-from-database-closed\/#article","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/solved-android-app-fetching-data-from-database-closed\/"},"author":{"name":"Kirat","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31"},"headline":"[Solved] Android app . fetching data from database [closed]","datePublished":"2022-10-20T16:28:54+00:00","mainEntityOfPage":{"@id":"https:\/\/jassweb.com\/solved\/solved-android-app-fetching-data-from-database-closed\/"},"wordCount":292,"publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"keywords":["android"],"articleSection":["Solved"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/jassweb.com\/solved\/solved-android-app-fetching-data-from-database-closed\/","url":"https:\/\/jassweb.com\/solved\/solved-android-app-fetching-data-from-database-closed\/","name":"[Solved] Android app . fetching data from database [closed] - JassWeb","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/#website"},"datePublished":"2022-10-20T16:28:54+00:00","breadcrumb":{"@id":"https:\/\/jassweb.com\/solved\/solved-android-app-fetching-data-from-database-closed\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jassweb.com\/solved\/solved-android-app-fetching-data-from-database-closed\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/jassweb.com\/solved\/solved-android-app-fetching-data-from-database-closed\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/jassweb.com\/solved\/"},{"@type":"ListItem","position":2,"name":"[Solved] Android app . fetching data from database [closed]"}]},{"@type":"WebSite","@id":"https:\/\/jassweb.com\/solved\/#website","url":"https:\/\/jassweb.com\/solved\/","name":"JassWeb","description":"Build High-quality Websites","publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jassweb.com\/solved\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/jassweb.com\/solved\/#organization","name":"Jass Web","url":"https:\/\/jassweb.com\/solved\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/","url":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","contentUrl":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","width":693,"height":132,"caption":"Jass Web"},"image":{"@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31","name":"Kirat","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/","url":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1776403586","contentUrl":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1776403586","caption":"Kirat"},"sameAs":["http:\/\/jassweb.com"],"url":"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/"}]}},"_links":{"self":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/16611","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/comments?post=16611"}],"version-history":[{"count":0,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/16611\/revisions"}],"wp:attachment":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/media?parent=16611"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/categories?post=16611"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/tags?post=16611"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}