简体   繁体   中英

How to access a remote mysql database using java

I have already developed a JAVA SWING Application . I want to install this application in several computers which all have access to internet . So where should I place my MYSQL Database ? All these computers should have the ability to access the same database via the internet.

It's not very common to allow access to a database directly over the internet for security (authentication authorization, encryption) and performance reasons. In most cases, you would create a web-based server application which can perform database operations, enforcing business, domain, and security rules. The client application makes calls over the internet (using REST calls, AJAX calls, or something proprietary), and gets the results back from the server.

In your case, since your client software is Java, you may want to research Java Servlets and run something lightweight like Tomcat as a serer.

Please see this page and this page for an explanation of client-server relationships.

  1. Put your database in host that is accessable by Internet.
  2. For each of the external ip addresses of each of the Applicaton host create a user on mysql.

     GRANT ALL PRIVILEGES TO database.* to `user1`@`APPLICATION_HOST_IP` identified by 'PASSWORD'; 

Now user1 will have access from APPLICATION_HOST_IP IP.

Well the possibility is limitless.. You can place it on every computer that is accessible by the others. As long as you can acces the database via network it does not really matter where it is. But if the Computers with your client Swing are all connected in LAN, than store the DB on the computer with best Performance. As a tip use the IP, and port dynamicaly from text or entry, so u do not recompile every time u change the IP. Chiers!!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM