简体   繁体   中英

Client Application Connections to MySQL

I am making a Java small program for some myself and some friends that we will use to work on projects together.

The program relies on MySQL for data but I don't want every one of the client machines (20 in total) connecting to the database directly because it leaves too much exposed on the server side.

What method is used in large corporations where multiple client machines running some program which uses data stored in MySQL. Surely they do not all connect to the database directly??

BTW - Lets keep this confined to Java please

Often the solution is to have a single web-app that all the Java clients connect to, and it is that web-app that talks to the database. You would give the web-app the credentials and permissions it needs to perform the DB operations you want.

Often, you also have the Clients identify themselves through some means (password authentication is common). And then the web-app keeps an audit log (either in DB or in a file) in order to keep track of who did what, in case of problems that arise.

You can handle it with Spring BasicDataSource, look at more voted answer for this question and here is another example

Also take a look at MySQL connection pooling doc

If you want every machine connect to same java-handled pool I would create two applications, one that access data through datasource with connection pooling and exposes web/rest services. Second application could consume those services from 20 or more machines.

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