0

I know how to connect to computer's mysql database using java, but I don't have idea what IP i will use when there are so many computer on same network. Lets say there are three computer at my home using same Wi-Router but one of them has the database installed. Also How to connect a computer's database that are internal to an access point having same public IP.

4
  • Port forwarding from the router basically, although it's not a good idea to expose a database port to the outside world. Commented Aug 12, 2016 at 9:33
  • If the MySQL server is running on windows then open cmd and type ipconfig that will tell you what local IP address the computer is using, if it's running on linux you can use ifconfig. You can then connect to that host using the local IPV4 displayed. You should also edit your question tag, it's not relevant to java. You'll require port-forwarding to achieve the connection and also, remote login may be required on the MySQL config. Commented Aug 12, 2016 at 9:34
  • Yeah its Port forwarding, and the configurations may vary depends on the router. Commented Aug 12, 2016 at 9:34
  • what extra information in java code ? Public IP+port no+ what else???? Commented Aug 12, 2016 at 10:03

1 Answer 1

1

Connect to an external or internar DB Server it's irrelevent for Java. You will define a URL like this <IP>:<port>/<DB_Name> in both cases.

  • If your java server is inside your local net you should use the private IP of the DB server.

  • If your java server is in an external net you should use the Public IP and the port you've defined in your NAT. Yoy will need to configure the port forwanding, that means: Tell your NAT that all the incomings request for port X should be redirected to the DB server. This is all router's configuration, not java code.

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

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.