+ 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

27th Jun 2021, 11:00 PM
Arif Nasery
Arif Nasery - avatar
10 Respuestas
+ 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.
28th Jun 2021, 4:21 AM
David Carroll
David Carroll - avatar
+ 3
Thanks from all of you I changed my firewall port and then creat a new username and password it works well ❤️❤️
28th Jun 2021, 6:30 AM
Arif Nasery
Arif Nasery - avatar
+ 2
28th Jun 2021, 12:36 AM
A͢J
A͢J - avatar
+ 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?
28th Jun 2021, 4:20 AM
David Carroll
David Carroll - avatar
+ 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)
28th Jun 2021, 5:37 AM
A͢J
A͢J - avatar
+ 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!
28th Jun 2021, 3:25 AM
Shahghasi Adil
Shahghasi Adil - avatar
+ 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 ^^
28th Jun 2021, 3:27 AM
visph
visph - avatar
+ 1
David Carroll yep true!
28th Jun 2021, 4:41 AM
Shahghasi Adil
Shahghasi Adil - avatar
0
I try it but it's not working
28th Jun 2021, 3:43 AM
Arif Nasery
Arif Nasery - avatar