0

i have done one java project that using the jdbc to connect with my localhost server (ms server). I don't know how can i connect my localhost database to another machine to run this project?

0

2 Answers 2

1

Please provide more information for a better anwer :)

Depending on your need, you either need to make your machine & DB accessible from another machine, or every machine will need its own database.

You may also want to separate Server and Client side, where the Server app will be deployed on your machine, have access to the DB and do the logic, and the other machines will only need the Client app that will contact your Server (you'll still need to make your machine accessible).

Sign up to request clarification or add additional context in comments.

Comments

0

If your Database is not accessible to the internet and the other machines are not on the same network, then you will not be able to connect to it. In both cases you need to configure your host machine to allow connections to the specific port you are using for the database. You also need to know your IP of the host machine.

For example: If you are using MySQL as your DB, it defaults to port 3306. You would need to configure rules for both your local network firewall to allow incoming/outgoing connections on that port (or another port that you then forward to 3306), and also configure your host machine to allow incoming/outgoing connection.

The safest way to do this would be to establish an SSH connection, otherwise you are just opening yourself up for all kinds of attacks from the web.

In your code: You will have to point your JDBC connector to the IP address and port of the server you are trying to connect to.

For example:

private final String server   = "jdbc:mysql://<HOST IP>:3306/<DB TABLE>";
private final String userName = "<USERNAME>";
private final String passwd   = "<PASSWORD>";

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.