When you go to connect Java with the database (in the case of Mysql), you typically do something like this:
Connection con = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/basededados", "usuario", "senha");
Note that in the first parameter you have a URL. If in it, instead of you use localhost
, use an IP or host name, that’s where it will connect. Thus, you give the network location where the database is, and therefore the database does not need to be on the same machine where your Swing program runs. This command will only be executed when the program is running, never during the build. Because it may be that the user or seha, or even the URL itself, is read from the user or some configuration file.
You compile the program without the database, just put in the classpath or modulepath the JAR needed to connect to it at runtime. You do not need the database to compile the program.
It might even make sense for you to install Mysql on the same machine where the Swing program would run. But if you need two or more machines accessing the same database instead of separate database, it would only be installed on a single machine and accessed via IP or hostname.
To class DriverManager
and the interface Connection
are in the bundle java.sql
. This is the package that contains the classes and interfaces needed for your program to use any database. However, the connection to the same database is managed by the connector, which in the case of Mysql, can be downloaded here. In general, for each different database type, you will need a different specific connector.
This has nothing to do with JAVA. Mysql is a separate product. If you want to use Mysql, you need to install Mysql on at least ONE of the client’s network machines. If you don’t want this feature, you can choose another of endless ways to store data with java. It would be nice to [Dit] your question and be clearer on what you really need. If it’s just 'talk' about it to get situated, it would be better to make a few dots with more specific questions to be able to participate in the network chat.
– Bacco
Not that I consider this to be one of the best questions on the site, but in my opinion it is perfectly valid. Unless someone tells me otherwise, I disagree with who votes to shut it down.
– Victor Stafusa
I don’t agree with the downvotes either. As absurd as it may seem some questioning (mainly for the great sages of the site), who asks and needs a clarification.
– Joao Paulo