可以连接到MySQL数据库:com.mysql.cj.jdbc.exceptions.CommunicationsException:通信链接失败

时间:2019-01-21 16:07:37

标签: java mysql jdbc

我正在尝试连接到本地MySQL服务器,但是在安装xampp之后无法做到这一点

这是Java代码

   public class Testjdbc {
    public static void main(String[] args) {
    String jdbcUrl = "jdbc:mysql://localhost:3306/hb-01-one-to-one-uni? 
    userSSL=false";
    String user = "hbstudent";
    String pass = "hbstudent";
    try {
        System.out.println("Connecting to database... " + jdbcUrl);
                    Connection connection =              
        DriverManager.getConnection(jdbcUrl, user, pass);
                    System.out.println("Connection Successfull");
                }catch (Exception e) {
        // TODO: handle exception
        e.printStackTrace();
    }
}
}

和错误:

Connecting to database... jdbc:mysql://localhost:3306/hb-01-one-to-one-uni? 
userSSL=false
com.mysql.cj.jdbc.exceptions.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.
at com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:174)

0 个答案:

没有答案