4

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:

  1. 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.

  2. 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.

2
  • 1
    The best thing would be to run the REST service on the same local network as DB is. Commented Nov 20, 2012 at 10:02
  • here you will find some answers about which one is best. Commented Nov 20, 2012 at 10:05

2 Answers 2

0

Sounds like a big task, and I'm not sure there are any easy answers. You most certainly should not expose connections to your database to the internet, as that would be a powerful vector for potential attackers.

A web service would be a very good solution to this. The Java standard for RESTful webservices is JCR (JSR-170), the reference implementation for which is Apache Jackrabbit (http://jackrabbit.apache.org/). Its pretty easy to set up, and there are various options for securing such a service.

Edit: No thats wrong! I meant JAX-RS and Jersey (http://jersey.java.net/). Sorry!

Sign up to request clarification or add additional context in comments.

Comments

0

Easiest solution would be to set up a VPN allowing your remote clients to connect to the same database. That takes care of the security and infrastructure considerations, and requires no change to your application.

The service-based approach is second favourite - it's a fundamental re-build of the application, and usually brings a lot of tricky performance and scalability issues. I'd recommend reading Martin Fowler's Patterns of Enterprise Integration for a recommendation - it's a far more complex issue that you can expect to answer on SO.

Do not open up your MySQL database to the wider internet - the security risks are simply too big.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.