+ 2
How I can connect to another computer database in java?
I connect by ip address from one pc to another pc database it work as well but how can I get connecting by java to this pc database The database I used is mysql And the server is xampp
11 Antworten
+ 4
My guess is you need to add the proper GRANT privileges which apply to the user / remote IP / and database.
You may also need to open your firewall on DB02 to allow remote connections on port 3306.
But... this is a wild guess since your question is so ambiguous.
+ 3
Thanks from all of you
I changed my firewall port and then creat a new username and password it works well ❤️❤️
+ 2
Arif Nasery
Step by step explanation is given here.
https://codeforgeek.com/java-mysql-connectivity-jdbc/
+ 2
Arif Nasery The following are unclear from your question:
1. How exactly did you "connect by ip address from one pc to another pc database?"
Let's refer to these "PCs" as DB01 (MySQL) and APP01 (Java program). It will help keep things clearer.
2. When you tested your connection, was it from APP01 or another PC? If another PC is involved, let's refer to this as APP02.
3. Are you saying you were able to connect to a database on DB01, but you aren't able to connect to a database on another PC? If so, let's refer to the 2nd database as DB02.
4. Assuming there are two databases, one that you can connect to (DB01) and one you cannot (DB02), was your connection to DB01 from the Java program in question?
5. If this is about changing the connection for a Java program on APP01 from DB01 to DB02, have you attempted to connect to DB02 via MySQL Shell?
+ 2
Arif Nasery
S-Adil 👑 🇦🇫 __active__
To connect your Java code with database (which is located at another IP) you have to define some inbound/outbound rules in firewall and also port number should be open means should be accessible from outside.
The procedure to connect java with database server is same as we have shared links but in that jdbc connection we have to provide IP address of database server (Remote PC where database exist)
+ 1
Arif Nasery
Just supply the IP / hostname of the remote machine in your database connection string, instead of localhost. For example:
jdbc:mysql://192.168.15.25:3306/yourdatabase
Make sure there is no firewall blocking the access to port 3306
Also, make sure the user you are connecting with is allowed to connect from this particular hostname. For development environments it is safe to do this by 'username'@'%'. Check the user creation manual and the GRANT manual.
visph
🅰🅹 🅐🅝🅐🅝🅣
Martin Taylor
You didn't understand what he means!
+ 1
S-Adil 👑 🇦🇫 __active__ OP said he was able to connect from one pc to another one, so the problem is how to connect with java, not how to connect to another ip than localhost ^^
+ 1
David Carroll yep true!
0
I try it but it's not working