0
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.

I Surrender I already tried the best that I can Please help me I just need to make a connection to my database

I am using hostinger.ph as the hosting site of my database

DBconnect.java

package mftis;

import java.sql.*;

public class DBconnect {
private Connection con;
private Statement st;
private ResultSet rs;

public DBconnect(){
try{
    Class.forName("com.mysql.jdbc.Driver");
    System.out.println("Success in using the Driver");

    con =            DriverManager.getConnection("jdbc:mysql://mysql.hostinger.ph/u366906409_mftis","u366906409_mftis","mftis2016");
    st = con.createStatement();

}catch(Exception e){
    System.out.println(e);
}
}

}

login_window

private void btnLoginActionPerformed(java.awt.event.ActionEvent evt) {                                         
    DBconnect connect = new DBconnect();
}

Please I will really appreciate the help anyway my Database is over the internet all the tutorials i can found is using localhost

Jaypee Tan
  • 101
  • 1
  • 10

1 Answers1

0

Try something like this

Class.forName(driverClass).newInstance();
        Properties connProp = new Properties();
        connProp.setProperty("user", properties.getDbUser());
        connProp.setProperty("password", properties.getDbPasswd());
        connProp.setProperty("connectTimeout", timeout);
        connProp.setProperty("socketTimeout", timeout);
        return DriverManager.getConnection(dburl,  connProp);

Where dburl is :

String url = "" + properties.getDbServer() + ":" + properties.getDbPort() + "/" + properties.getDbName();

            url = "jdbc:mysql://" + url + "?zeroDateTimeBehavior=convertToNull";

        return url;
Hooch
  • 487
  • 3
  • 11