I'm working on a Swing GUI application that among other things, functions as a database client that reads and writes to a MySQL database. Currently I implemented the interaction with the database using JDBC (as instructed here: http://www.kitebird.com/articles/jdbc.html), which directly connects to the database by specifying the explicit database host name (IP address).
This works fine as long as I run the GUI client application on a PC which is a part of the organization's local network, and thus I can reach the MySQL database by specifying the IP address of the machine it's deployed on.
But I wonder what is the proper way of implementing the interaction with the database if the GUI client application to be run on a computer that's outside of the organization's network (communicating over the internet)?
The two ways I could think of are:
Configure the database server machine to be available on MySQL's default port (3306) over the internet, and then I would be able to continue connecting to the database from the GUI client application by specifying the database server's IP address.
Create a web service (probably REST API based), that would run on the database server machine, and function as a middleman between the GUI client and the MySQL database.
I suspect the correct way is the second option, using a web service, but I don't have any experience in implementing any.
So my bottom line question is:
What is the correct way to implement communication with a database over the internet, and if it involves using web services, where should I start? What are the common libraries or frameworks that are used for implementing such things?
Thanks a lot to anyone who had the patience to read all this.