I'm writing an Android application using Java and AndroidStudio as IDE; my application should communicate with the MySQL database that is hosted on a different machine than the one I'm launching my java code: the machine on which the MySQL server is running is an ubuntu machine, while the machine on which the java code is launched is a Windows machine (just to let you know). I'm using the java.sql.* library, so I create the connection with
Connection myConn = DriverManager.getConnection(url, username, password);
where username and password are the one that I insert to log in the database server, while the url parameter should be the url of my MySQL server; here is the problem: I don't know what I should write as url: the syntax should be
jdbc:mysql://<HOST_NAME>:<PORT>/<DB_NAME>
but apparently I don't know the HOST_NAME of my database because when I run the program the exception "Connection refused" is launched
I already have:
- set MySQL connector/j as library in the project and specified the correct path for the .jar file
- run the command
sudo ufw allow mysql
on the ubuntu machine - started the db
How can I connect to my database?