0

I have create a simple Java desktop app in Eclipse. I use jdbc mysql plugin to connect to my database. The program runs fine when the database is local i.e on WAMP but when I add an online database. It gives me a Communication links failiure, The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server..

I tried to check if my firewall is blocking it or not using telnet but when I run telnet subinfo.xyz 2082, it just goes blank.

I think the jdbc:mysql://subinfo.xyz:2082/subinfo_hsy123 is not right. Is there any other way to connect to an online database?

package application;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;

public class DbConn {
    // is this the right way to to do?
    String url = "jdbc:mysql://subinfo.xyz:2082/db1";
    String user = "username";
    String password = "password";
    public Connection conn;
    public Connection connect(){
        // Load the Connector/J driver
        try {
            Class.forName("com.mysql.jdbc.Driver").newInstance();
        } catch (InstantiationException e) {
            Alert alert = new Alert(AlertType.ERROR);
            alert.setTitle("Error Dialog");
            alert.setHeaderText("Error Occured!");
            alert.setContentText("Ooops, Please check internet or make sure you have working hosting plan!");
            alert.showAndWait();
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
Hassan Yousuf
  • 751
  • 6
  • 12
  • 24
  • What do you mean, *but when I run `telnet subinfo.xyz 2082` it just goes blank*? You should see "Connected to subinfo.xyz.". If you don't, it could indeed be caused by a firewall that's dropping packets. – Arjan Aug 28 '16 at 06:24
  • I think your MySQL configuration is not correct. You may need to check my.cnf or (my.ini in Windows) to see if it knows your host name IP Address or not. At the meantime, you can narrow it down with changing your URL to IP Address to see if it works. Alos, check http://stackoverflow.com/questions/6865538/solving-a-communications-link-failure-with-jdbc-and-mysql – Saleh Parsa Aug 28 '16 at 06:24
  • @Arjan I open cmd and then I type `telnet`, Then I enter this command `open subinfo.xyz 2082` and then after sometime, it says `Connection to host lost`. – Hassan Yousuf Aug 28 '16 at 06:29
  • @SalehParsa Are you talking about the MySQL configuration on my computer or on my hosting server? – Hassan Yousuf Aug 28 '16 at 06:31
  • Your host because as you said it works fine in your local machine – Saleh Parsa Aug 28 '16 at 06:31
  • http://stackoverflow.com/questions/2839321/connect-java-to-a-mysql-database?rq=1 – Sanka Aug 28 '16 at 06:41

0 Answers0