what is the best architecture to connect to a remote mysqlserver (database) from java swing standalone client app over the internet without using middle server
JDBC would be the best
try
{
Class.forName("com.mysql.jdbc.Driver").newInstance();
String url = "jdbc:mysql://HOST/DATABASE";
conn = DriverManager.getConnection(url, "username", "password");
doTests();
conn.close();
}
Here is a collection of connectionstring to use on different databases
http://devdaily.com/java/jdbc-connection-string-mysql-postgresql-sqlserver
If you want to connect from stand alone application swings then JDBC is best suited.
You will definitely want to familiarize yourself with concurrency issues in Swing, as well as constructs like the SwingWorker and SwingUtitlies.invokeLater (see link below). Making remote calls from within the EventDispatchThread will hang your GUI and provide a very bad experience to your users.
You generally do not want to expose your database directly to the internet. IMHO you should really think about putting a (web or application) server in between. If you want to or have to, however, you should put real effort into securing it: very strong passwords, very restrictive permissions on everything, using SSL with client certificates or possibly even setting up a VPN ... Then this becomes less a question of programming than configuration and serverfault is a good place to get more information.
I found two interesting related questions on Serverfault that deal with this issue (not MySQL though):
- The wisdom of exposing a database server on the internet?
- How to expose SQL 2008 database to the world through the Internet?
From an architecture point of view, even with a thick client I would prefer to have a web server in between that uses SOAP or REST to provide database functionality to the client app.