How To Connect Android with Servlet MySQL

How To Connect Android with Servlet MySQL

How To Connect Android with Servlet MySQL

Creating a web service application in android is an easy task, but to connect android with servlet MySQL is a bit complex. One of our users has requested for this tutorial. So if you are one of those who want to connect android with servlet MySQL then I must tell you, my friend, you are absolutely in the right place. This post is a detailed step by step user-friendly guide on how to connect android with servlet MySQL. In case while following the step you found something confusing or you have a question in that situation, do shoot us a comment and we will get to you with the solution asap.

How To Connect Android with Servlet MySQL

Servlet is basically a technology that is used for the creation of Web-based applications or Web applications. A servlet basically resides at the server-side and its work is to generate a dynamic web page. What makes Servlet technology strong and scalable is Java Language. Servlet technology is kinda a successor of CGI (Common Gateway Interface) language. CGI was a server-side programming language. There are different interfaces and classes in the Servlet API those are Servlet, GenericServlet, HttpServlet, ServletRequest, ServletResponse, etc.

As a whole, a Servlet is a java programming language which can extend the potential of servers that host applications accessed by means of a request-response programming model. The javax.servlet and javax.servlet.http packages provide interfaces and classes for writing servlets.

Now that we have a basic understanding of what a servlet is and its uses. Let us proceed further and discuss its main features of the servlet. The first important feature of Servlet is its Portability. As I have discussed above that Servlet uses JAVA Language and Since java is an Independent platform so is the Servlet.

One of its instances is, suppose you created a servlet on Windows that users GlassFish as a web server and later run it on any other operating system like Unix, Linux with Apache tomcat web server, this is what makes a servlet portable as compared to CGI.

A Servlet is very Efficient and Scalable. Once you deploy and load a servlet on a web server it can instantly start fulfilling requests of clients. A servlet is very Robust, backed by the top features of java like Garbage collection, Exception handling, Java Security Manager, etc; Servlet are very good a memory management and are less prone to memory leaks.

 

How To Connect Android with Servlet MySQL

My SQL is an open Source, free to use Relational Database Management System (RDBMS) that uses Structured Query Language (SQL). SQL is one of the best languages for three things adding, accessing and managing content in a database. So before explaining what My SQL is you need to understand the basic concept first. Suppose there is a company and the company needs to store the details of a hundred employees working in that company in such a way that all the employees can be individually identified. In that case, the first thing the company does is it collects the data from the employees. When I say data I mean the company collects the distinct pieces of information of an object. So when the company needs to store the information of hundreds of employees, it collects distinct pieces of information of all the employees so that the employees can be identified.

So now you have a large amount of data and you obviously need a place to store it right?. The place to store all the data is basically known as Database, you can consider a Database as a container where you can store all the data, but to access a huge amount of data you need proper management. This is where the term Database Management System comes and the most common DBMS used is My SQL. Powered by Oracle my SQL is an Open Source Database Relational Management System that works on many platforms

I hope now you have a clear idea of My SQL and how it works. So let’s talk about is features now. My SQL database provides their user with high-performance and scalability so that it can easily meet the demands of exponentially growing data loads and users. The feature of Self-healing clusters improves scalability, performance, and availability. It also has Online Schema Change to meet changing business requirements and lots more.

TUTORIAL PART

Below I have attached a video that you will show a detailed step by step user-friendly guide on how to connect android with servlet MySQL. In case while following the step you found something confusing or you have a question in that situation, do shoot us a comment and we will get to you with the solution asap.

 

Important Codes

android-async-http is a popular third-party library that will help us to handle the entire process of sending and parsing network requests for us in a more robust and easy-to-use way.

For Setup
Add this library to our app/build.gradle file:

For Setup
dependencies { compile ‘com.loopj.android:android-async-http:1.4.9’ }

 

Sending a Network Request
import com.loopj.android.http.*; import cz.msebera.android.httpclient.Header; AsyncHttpClient client = new AsyncHttpClient(); RequestParams params = new RequestParams(); params.put(“key”, “value”); params.put(“more”, “data”); client.get(“http://www.google.com”, params, new TextHttpResponseHandler() { @Override public void onSuccess(int statusCode, Header[] headers, String res) { // called when response HTTP status is “200 OK” } @Override public void onFailure(int statusCode, Header[] headers, String res, Throwable t) { // called when response HTTP status is “4XX” (eg. 401, 403, 404) } } );

 

Sending a JSON Request
String url = “https://ajax.googleapis.com/ajax/services/search/images”; AsyncHttpClient client = new AsyncHttpClient(); RequestParams params = new RequestParams(); params.put(“q”, “android”); params.put(“rsz”, “8”); client.get(url, params, new JsonHttpResponseHandler() { @Override public void onSuccess(int statusCode, Header[] headers, JSONObject response) { // Root JSON in response is an dictionary i.e { “data : [ … ] } // Handle resulting parsed JSON response here } @Override public void onFailure(int statusCode, Header[] headers, String res, Throwable t) { // called when response HTTP status is “4XX” (eg. 401, 403, 404) } });

 

Video Soure: hansraj Padvi   Code Source: androidwebservices02

I hope you liked the tutorial for more do subscribe Tech Decoders.

 

Add Comment