Jason
Jason

Reputation: 1059

Public Java Swing App connect to database

I am developing a Java Swing app used by the public. This app requires connection a mysql database. Should I connect to the database straight from the Java Swing app?

Upvotes: 2

Views: 207

Answers (1)

Nándor Előd Fekete
Nándor Előd Fekete

Reputation: 7098

It depends on how much you trust your clients. Exposing your whole database to external networks can be risky, because a malicious user could easily reverse engineer your program to find out the credentials to connect to your database. While you could defend to some extent from the risks associated with this by pushing down security to the database, a proper service layer written in a general purpose programming language like Java would be much more suitable for this. And with a proper service API to access your database you could make much higher guarantees for data consistency in your database. Later, you could even switch between database vendors or even switch to another storage method like a NoSQL solution, while keeping the Swing client practically unchanged (given a properly designed service API). On the long run, it would be definitely worth the effort.

EDIT: follow up answer on how to implement such a web service

If you want to minimize external dependencies, you could go with a solution based purely on Java standards, like JAX-WS. It's available as part of the JavaEE platform, so, while not strictly necessary, it's probably a good idea to use a compliant implementation, as it provides services like declarative transactions, authentication and authorization, and many more things that you might need while implementing and exposing your service API. Spring Framework is a popular alternative for JavaEE if you want total control over your backend service layer, but it would probably take much more up-front investment in terms of learning curve. You can connect to either JAX-WS services or Spring Remoting from Java SE apps, so both can be a viable path to achieve a proper 3-tiered architecture.

Upvotes: 2

Related Questions