2

I have developed a desktop java application and created its DB by using easyPHP. I have connected 2 computers with IP address 192.168.1.2 for the first one and 192.168.1.3 for the second one. Now I want to put the easyPHP on the first computer and the application on the second computer, but I have problem with the connection. The code which has been used for the connection is:

    public DataSource getDataSource(){ 
     BasicDataSource ds = new BasicDataSource(); 
     ds.setDriverClassName("com.mysql.jdbc.Driver"); 
     ds.setUsername("root"); 
     ds.setPassword(""); 
     ds.setUrl("jdbc:mysql://192.168.1.2/en_library"); 
     ds.setMaxActive(20); 
     ds.setMaxIdle(4); 
     return ds; 
    }

It gives me this error message:

    Feb 10, 2015 11:41:01 AM UserSearch.UserSearch <init> SEVERE: null
    org.apache.commons.dbcp.SQLNestedException: Cannot create
    PoolableConnectionFactory (Communications link failure 

SOLVED:

I have done the following steps:

1- Open port 3306 from firewalls

2- Grant all privileges to my user through GRANT ALL PRIVILEGES ON en_library.* TO 'root'@'%' IDENTIFIED BY 'PASSWORD'

3- Change bind-address : 0.0.0.0

4- restart MySQL

5- In the connection URL write ("jdbc:mysql://192.168.1.2:3306/en_library")


Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Mohammed Mohammed
  • 403
  • 1
  • 9
  • 18

1 Answers1

1

You should add more port, since 3306 is MySQL's default port, we have:

ds.setUrl("jdbc:mysql://192.168.1.2:3306/en_library"); 

and remember put connection string snippet into a try-catch block.

Vy Do
  • 46,709
  • 59
  • 215
  • 313