1

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)

O. Jones
  • 103,626
  • 17
  • 118
  • 172
mustafa
  • 33
  • 1
  • 7
  • Is there a causedby clause in your error? You are not able to connect to your mysql running instance. Is it running? Is the username/password correct? is there any firewall? – JCompetence Aug 23 '21 at 10:51
  • @SusanMustafa username and password are correct however I'm using vpn is there's anything to do with it? – mustafa Aug 23 '21 at 10:53
  • is 3300 the correct port used?? Generally its 3306 – JCompetence Aug 23 '21 at 10:54
  • @SusanMustafa yes It's – mustafa Aug 23 '21 at 10:55
  • 1
    try to telnet to it from your command line (without using java) telnet localhost 3300 or telnet localhost 3306 and see if you can connect. If you can connect then something else in your code needs to be looked it....but if you cant telnet, its your network/vpn – JCompetence Aug 23 '21 at 10:56
  • You're trying to connect to your server using Transport Layer Security (TLS or SSL). That's because your connection string says `?useSSL=true`. Your error message hints at TLS not functioning (*protocol is disabled or cipher suites are inappropriate.*) 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. – O. Jones Aug 23 '21 at 11:17
  • I vote to reopen. This question is due to a problem connecting with SSL / TLS, and the linked duplicate question does not address that problem. – O. Jones Aug 23 '21 at 11:19
  • @O.Jones no bro same problem even after removing SSL – mustafa Aug 23 '21 at 11:25
  • Recent versions of Java disabled older TLS versions and certain ciphers. If that is the cause, you either need to enable them again in the `java.security` config file, or you need to upgrade your server so it uses more modern versions of TLS. – Mark Rotteveel Aug 23 '21 at 13:44

1 Answers1

1

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.

O. Jones
  • 103,626
  • 17
  • 118
  • 172
  • Yes It's something wrong with my db configurations as when I ran it on MAMP server it worked fine. – mustafa Aug 23 '21 at 11:35