Android Login and Register Using Restful Web Services (Java + MySQL)

Here you will learn to make android login and register system using restful web services in java and mysql.

In this tutorial I will teach you to develop a very simple android app for login and register system. This system sends the login or register request to the restful web service that is running on local server.

If you don’t know how to make restful web services in java and use it in android then I would highly recommend you to first read below tutorials.

Also Read: Create Simple Java RESTful Web Services Using Jersey

Also Read: Android Restful Web Service Client Example

Android Login and Register Using Restful Web Services (Java + MySQL)

Android Login and Register Using Restful Web Services (Java + MySQL)

Create Restful Web Service

I have used MySQL database in this web service. Make a login table in database with following schema.

mysql database login schema

 

Below is the code for restful web service developed in Java.

DemoService.java

 

Create Android Project

Make a new android project with package name com.loginandregister

For sending and fetching data from server I am using Volley library. So add its dependency in build.gradle file.

 

Read below tutorial if you don’t know how to use volley library.

Also Read: Android Volley Tutorial With Example

 

As we are doing network related operation so add internet access permission in AndroidManifest.xml file.

 

Now create three activities in the project Login, Register and Home. Add following code in the respective files.

Login.java

 

activity_login.xml

 

Register.java

 

activity_register.xml

 

Home.java

 

activity_home.xml

 

Make sure the web service is already running on the server. Also change the IP 192.168.1.8 in the URL with the IPv4 of your local system. You can find the IPv4 in windows by typing ipconfig command in command prompt.

Finally run and test the project.

 

Screenshots

login

register

home

 

The whole code is very simple and self-explanatory. If still you are facing any problem then feel free to ask in comment section.

22 thoughts on “Android Login and Register Using Restful Web Services (Java + MySQL)

  1. Pushkar Zagade

    Hay,
    The Above code are not able to connect to database. It Show com.android.volly.NoConnectionError java.net.connectException failed to connect to 127.0.0.1. It Show exception in emulator with Toast.

    Reply
  2. Matheus Vinicius

    Estou com erro conexao ver se esta certo?

    *Login.java
    String URL = “http:///10.105.75.149:8080/JavaRESTfullWS/DemoService/login”;

    *DemoService.java
    final static String url = “jdbc:mysql://localhost:8080/webservice”;

    webservice é o nome do meu banco

    Reply
  3. Ashith VL

    Can you write an example for CRUD operation please,..It will be helpful…

    Reply
  4. Nidhi

    I am getting error: BasicNetwork.performRequest: Unexpected response code 404
    Checked with all solution
    my URL: 10.0.0.155/webservice/Service/login

    Reply
  5. adi

    In your class demo.java i seen user and password with plain text. It’s so riskcan buddy. You can encryption them. Willy this unrecommended .just comment to get good result maybe in the future.

    Reply
  6. Raju

    can you please send me full code for the above example ..I getting error in webservice page.

    Reply
  7. raj

    I am getting error stating “com.android.volly.ServerError”
    can you please explain me on how to set the string URL

    Reply
  8. keerthi

    i’m getting error as com.android.volley.NoConnectioError.
    i dint understand how to give the url please help me in these two cases

    Reply
  9. keerthi

    can you please help me out in creating a web service for a android project.

    I will be so graceful.
    thanks in advance

    Reply
  10. farhad

    first thanks for this project

    please put web.xml file for this project in site

    Reply
  11. Luis

    What do i need to change if I want to consume and produce Json instead.

    Reply
  12. Soccerway

    I have used my IP address of my PC in the Url = http://[my ip address]:8081/MyFoodies/LoginRegisterWebService/login
    But still its throwing ‘Volley – time out error ‘
    > Switched off my Firewall settings
    > Tried this IP too 10.0.2.2
    > Tried Port no 8080, 8082, 8500
    I am using the ‘Remix OS Player’ emulator in my android studio.

    Set a break point in following step, but its not going inside ‘onResponse(String s)’ method …any idea what could be the problem ?
    StringRequest request = new StringRequest(Request.Method.POST, URL, new Response.Listener()

    Reply
  13. Shahid

    Hello Neeraj,
    I have seen your above example and i am 99% sure that i have done all perfectly but i am getting problem in one place may be you have faced it so plz help me in solving this.
    (I am using POST method).
    The problem is when i am testing Rest api using Postman Rest Client in browser the data is inserting properly and getting proper json response and also when i execute the same url from my Android Phone’s Chrome Browser it is working perfectly. But when i am setting value from Android app i am getting “null” (in Eclipse Log cat) and not inserting that value in MySql database.

    Reply
  14. Amy

    Hi,

    Could anyone tell me , from where is the URL present in Demoservice.java taken ?

    Reply
  15. seyda

    Hello,
    Program is running but I want the program to pull data in JSON format. How can I do this in ANDROID STUDIO program?

    Reply
  16. Jean Daboul MAXY

    i try this exemple and i get timeout error. can anyone help me please?

    Reply
  17. Burak

    This example does not work. Can you throw away the project codes

    Reply
  18. Planet7nodepositcasino

    If you desire to improve your knowledge only keep visiting this web site and
    be updated with the most recent gossip posed here.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.