Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to successfully access the database on another computer using java and jdbc and sql?

Tags:

java

mysql

jdbc

i have this database on another pc and i want to access it by using a connection string like this.

Class.forName("com.mysql.jdbc.Driver");
         con = DriverManager.getConnection("jdbc:mysql://192.168.0.1/dbtina","root","1234");

the "dbtina" is our database. the "1234" is our password. and we have configured our ip to be like that because we are using a wired connection (peer to peer).

Exception: Communications link failure

Last packet sent to the server was 0 ms ago.*

how do i fix this?

like image 600
Weddy Avatar asked Aug 31 '25 04:08

Weddy


1 Answers

Simply disable firewall. or open the port 3306 for mysql use this link if it helps

manually open port

even after doing this you might get security exception. use mysql GRANT query to give permissions.

mysql> GRANT ALL PRIVILEGES ON db_base.* TO db_user @'ip_address' IDENTIFIED BY 'db_passwd';

grant example

like image 134
Bhavik Shah Avatar answered Sep 02 '25 17:09

Bhavik Shah