Skip to content
Advertisement

Communication link failure in mysql jdbc driver

I’am not able to establish connection with mysql from java using this code

 Connection con=null;
    String dbUrl="jdbc:mysql://localhost:3300/sys?useSSL=true";
    String driver = "com.mysql.cj.jdbc.Driver";
    String userName = "root";
    String password = "cool123";

    Class.forName(driver).getDeclaredConstructor().newInstance();
    con = DriverManager.getConnection(dbUrl,userName,password);

It’s throwing me this error The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server. The driver has not received any packets from the server. No appropriate protocol (protocol is disabled or cipher suites are inappropriate)

Advertisement

Answer

You’re trying to connect to your server using Transport Layer Security (TLS or SSL). That’s because your connection string says ?useSSL=true. That’s a little strange when you connect to localhost — there’s no transport in or out of the server where your Java program runs, so using TLS costs lots of extra compute cycles for not much benefit, if you can even get it to work.

Your error message hints at TLS not functioning (protocol is disabled or cipher suites are inappropriate is TLS jargon.)

Try this connection string: jdbc:mysql://localhost:3300/sys (no TLS). It may work.

Then try this connection string jdbc:mysql://localhost:3306/sys . It uses the defaults.

Setting up a MySQL server to use TLS takes some server engineering work and knowledge. It’s possible that is not done correctly. If someone did it for you, ask that person for help.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement