The android application cannot communicate with mysql on the same system. Because when you launch an Android app, it runs inside the emulator. An emulator is a virtual mobile device , such as an Android device. The emulator itself has an IP address. Thus, according to the application ip 127.0.0.1 is an emulator ip, so the android application will try to establish a connection with mysql, which is located in the emulator. As you know, the emulator cannot have mysql in it, the connection will fail. You can use SQLite for data storage. If you want your Android application to communicate with mysql, you need to install mysql on another system and provide this ip system. Change the code as follows:
String url = "jdbc:mysql://192.168.1.102:3306/test";
Here I mentioned 192.168.1.102 - the second ip system. And do not forget to physically connect these systems before you try.
For additional knowledge: - Direct connection of mysql with the android application is not the right way. Create a web application that communicates with mysql. Add a web service to store data in mysql. In an android app, add a web tier that communicates with the web app through this web service. You can use xml or JSON to transfer data from an Android application to a web application through a web service. The web application must store data in mysql, which is accepted by calling the web service of the Android application.
Visruth
source share