4

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?

5 Answers 5

3

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

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

Comments

2

Open the 3306 port on the firewall of the computer where the DB is.

1 Comment

Well, first of all, you could provide some details...What OS are you using on the computer with the DB? What kind of firewall or antivirus software are you using there? Judging by your comment, I'd also like to ask what's the IP of the computer where the program is run...
1

You have to configure the firewall on the database computer to allow the traffic from different computer on specific Port.

Comments

1
GRANT ALL PRIVILEGES ON *.* TO 'USERNAME'@'%' IDENTIFIED BY 'PASSWORD' WITH GRANT OPTION;

Comments

-1

Change your code accordingly:

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

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.