'How does mySql database connection really work?
So whenever I make a connection to mySQL in javaFX I usually write something like this:
String url = "jdbc:mysql://localhost/" + dbName;
My question is how does the connection stays active if I move the app from one device to another?
I tried moving the app form my PC to my Laptop and it didn't connect, I also have the mySQL connector in the app's library.
I know this is probably a noob-ish question about how mySQL connections work but I couldn't really find anything on it.
Solution 1:[1]
The connection to database is a persistent physical connections. In the real life you will install the database and the clients (Java FX) in different machines, so you will have something like this:
- Machine A
- Mysql Database
- IP: 192.168.0.100
- Machine B
- Desktop PC with Java FX
- IP: 192.168.0.110
- Machine C
- Laptop PC with Java FX
- IP: 192.168.0.120
In order to connect from machine B and C to Mysql database you need to configure the Jdbc string connection to url = "jdbc:mysql://192.168.0.100/" + dbName;
Remember that localhost means: THIS MACHINE so if you put localhost in connection string, JavaFX will try to connect to a database in the same machine where it is running.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Ernesto Campohermoso |
