krotovic
krotovic

Reputation: 48

Couldn't connect to a MySQL DB via JWS app

Could someone help me with establishing connection with my DB on non-localhost server?

Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://"+SERVER+"/javadb?user=javadb&password=*****");

How could I set-up the SERVER String for my domain www.lmntstudio.cz? All required files are stored in one folder on the server.

I did it first on my localhost server and everything works well. But with the connection to another server is trouble.

Upvotes: 0

Views: 167

Answers (2)

pundit
pundit

Reputation: 312

I would recommend not to open MySQL connection from the client/user machine to the server. Because this would make your DB server open and prone to attacks.

Rather consider using web service. call that web service from your JWS application from client side and get the data.

Another point to consider is that opening a connection on a port say 3360 may be blocked by the firewall. If my firewall is set to block any out bound connection on port 3306 the connection could not be established.

Upvotes: 1

Prabhakaran Ramaswamy
Prabhakaran Ramaswamy

Reputation: 26094

Please ensure the MySQL is running in default port 3306 else you need change the port number accordingly.

     Connection connection = DriverManager.getConnection(  
                   "jdbc:mysql://www.lmntstudio.cz:3306/javadb", "username", "password");  

instead of www.lmntstudio.cz you can use ip of the domain.

run the following in the command line to get the ip

          cmd prompt> nslookup www.lmntstudio.cz

The Url syntax as follows

       jdbc:mysql://(host/ip):port/databasename", "username", "password"

Upvotes: 0

Related Questions