Bonjour à tous,

Je travaille avec NetBeans 7.3 / JDK 1.8

En Librairies, j'ai chargé :
MySQL JDBC Driver - mysql-connector-java-5.1.23-bin.jar!/

Pour me connecter, j'utilise régulièrement, à chaque requête :

Connection c = DBConnect.getConnection();

qui pointe vers :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
 
package piggybank;
 
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import org.controlsfx.control.action.Action;
import org.controlsfx.dialog.Dialogs;
 
/**
 *
 * @author Pascal
 */
public class DBConnect {
    private static Connection conn;
    private static String url = "XXXXX";
    private static String user = "XXXXX";
    private static String pass = "XXXXX";
 
    public static Connection connect() throws SQLException{
        try{
            Class.forName("com.mysql.jdbc.Driver").newInstance();
 
        }catch(ClassNotFoundException cnfe){
            System.err.println("Error cnfe: "+cnfe.getMessage());
            Action response = Dialogs.create()
            .title("Erreur")
            .masthead("Exception rencontrée")
            .message("Error ie: "+cnfe.getMessage())
            .showException(cnfe);
        }catch(InstantiationException ie){
            System.err.println("Error ie: "+ie.getMessage());
            Action response = Dialogs.create()
            .title("Erreur")
            .masthead("Exception rencontrée")
            .message("Error ie: "+ie.getMessage())
            .showException(ie);
        }catch(IllegalAccessException iae){
            System.err.println("Error iae: "+iae.getMessage());
            Action response = Dialogs.create()
            .title("Erreur")
            .masthead("Exception rencontrée")
            .message("Error iae: "+iae.getMessage())
            .showException(iae);
        }
 
        conn = DriverManager.getConnection(url,user,pass);
        System.out.println("SQL - Nouvelle connexion en cours");
        return conn;
    }
    public static Connection getConnection() throws SQLException, ClassNotFoundException{
        if(conn !=null && !conn.isClosed()) {
            System.out.println("SQL - Connexion en cours toujours active");
            return conn;
        }
        connect();
        return conn;
 
    }
Et régulièrement, la requête échoue avec en message Output :

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

The last packet successfully received from the server was 61*787 milliseconds ago. The last packet sent successfully to the server was 1 milliseconds ago.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
...


J'ai raté un truc?
Faut que je referme systématiquement chaque connexion? Mais je risque d'y perdre en performances, non?
C'est mon hébergeur (byethost) qui est pas terrible?

Par avance merci pour votre aide...