Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Desktop Application to connect to database

I have a desktop application and it makes use of JDBC. I have no problem with JDBC whenever I use localhost. Now, I am to connect to a server that does not allow remote connection. I was advised to provide a web service to serve as a gateway between my application and the database.

An alternative solution I can think of is, to look for a mysql server that allows remote connection. I find it difficult to look for tutorials where I can clearly understand web services in java. I've done some research and I was told I could use PHP to write a web service and generate JSON file, then I could parse it in java. But If I do that, all my JDBC codes have to be recoded/removed.

Is it possible to connect to the database remotely without having my JDBC codes removed? Or can I incorporate Tomcat with JDBC? Thank you!

Here's what I get..

Exception in thread "main" com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure Caused by: java.net.ConnectException: Connection timed out: connect

like image 371
user974227 Avatar asked Jul 29 '26 00:07

user974227


1 Answers

Your questions seems to be leading to an architecture similar to this: http://yuml.me/2cc6bd7f

But unlike what your question suggests - the Server Side Module doesn't relay DB queries from the desk-top application to the database - it acts as a server to your desktop application which becomes a client application.

This means re-architecturing (not a real word I think) of your application - but a common best practice. The server side module is responsible for authenticating and authorizing your users to ensure that no one can perform malicious activities on the database.

There is no short answer here - you need to consider if this is the direction you want to go with.

An alternative as others suggested is to allow direct access from the desktop application to the database via a firewall. I assume you are posting here since the people responsible for the database's integrity told you you shouldn't do that.

like image 99
RonK Avatar answered Jul 31 '26 13:07

RonK



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!