• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

com.mysql.cj.exceptions.CJCommunicationsException: Communications link failure ---> Only on MAC OS

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, any help is greatly appreciated.

I made an app that connects to a database and checks the version the user is running vs the latest version on my site. Everything runs smooth on Windows but on MAC OS, sometimes I get a Comms link failure. So I made a simple connection tester with some code from the internet to troubleshoot this on different MACs to try to narrow down the problem without running the entire app all the time. Luckily, this small code throws the same exception.

The database user has only SELECT privileges, the hostname is correct (tried both the hostname and ip), skip_networking on the database is off, I added the % wildcard to accept connections from all IPs and bind_address is commented out. I can ping the database from terminal on the machine but when I run this tester, it only prints "***** MySQL JDBC Connection To G4THER DBase Tester *****" and throws the exception. I'm fairly new to programming so I am kind of stuck.

here is the tester program to try to reproduce the issue:



here is the Log error I get when I run this in MAC OS Terminal. As I mentionned, all of this works great on Windows, never had any issue.

Last login: Thu Dec 12 12:25:13 on ttys000

Michaels-iMac:~ michaeldostie$ cd downloads

Michaels-iMac:downloads michaeldostie$ java -jar dbasetester.jar



***** MySQL JDBC Connection To G4THER DBase Tester *****

Cannot connect to database server

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)

at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:64)

at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:836)

at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:456)

at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:246)

at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:199)

at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:677)

at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:228)

at test.main(test.java:18)

Caused by: com.mysql.cj.exceptions.CJCommunicationsException: 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 java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)

at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)

at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)

at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481)

at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:61)

at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:105)

at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:151)

at com.mysql.cj.exceptions.ExceptionFactory.createCommunicationsException(ExceptionFactory.java:167)

at com.mysql.cj.protocol.a.NativeSocketConnection.connect(NativeSocketConnection.java:91)

at com.mysql.cj.NativeSession.connect(NativeSession.java:144)

at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:956)

at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:826)

... 6 more

Caused by: java.net.UnknownHostException: cpl81.hosting24.com: nodename nor servname provided, or not known

at java.base/java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)

at java.base/java.net.InetAddress$PlatformNameService.lookupAllHostAddr(InetAddress.java:930)

at java.base/java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1499)

at java.base/java.net.InetAddress$NameServiceAddresses.get(InetAddress.java:849)

at java.base/java.net.InetAddress.getAllByName0(InetAddress.java:1489)

at java.base/java.net.InetAddress.getAllByName(InetAddress.java:1348)

at java.base/java.net.InetAddress.getAllByName(InetAddress.java:1282)

at com.mysql.cj.protocol.StandardSocketFactory.connect(StandardSocketFactory.java:132)

at com.mysql.cj.protocol.a.NativeSocketConnection.connect(NativeSocketConnection.java:65)

... 9 more

Michaels-iMac:downloads michaeldostie$


Really would appreciate any help I can get. Thanks
 
Rancher
Posts: 144
9
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, first: it's not wise to post login credentials public - better you cover up at least the ip/hostname next time.
About the issue: You got an UnknownHostException - so the Mac can't resolve the hostname given - wich doesn't fit the code you posted wich uses an ip.
 
Mick Dostie
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for pointing all that out, sicne the user for the db only has select privileges I figured it was no big thing, I removed it from my questions, thanks.

I tried both IP and Hostname and both throw exception.
 
Kristina Hansen
Rancher
Posts: 144
9
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, currently an issue is that the code you posted doesn't match up the stacktrace: Initially you posted code wich used an IP address, but the stacktrace shows a hostname (I wrote the first reply on my phone as I was outside - but if I remember it pretty much shows up what I get when I ask my DNS) - so the DNS record itself seem to be ok - so, this looks like the Mac fails to do a correct DNS lookup.
I don't know Mac, but as it's a descendant of Unix (BSD) it still should have some of the basic POSIX tools available: "dig" - wich is a DNS tool. Open a terminal and type "dig <hostname> A" and see if it can correctly resolve the hostname to the IP. If so try a reverse lookup: "dig -x <IP>" wich should do a reverse lookup and get the hostname back (at least that's what I get - so the PTR seems also correctly set). If both succeeds it seems the Mac can resolve DNS correctly - then it could be an issue with the used VM - type "java -version" it should print out version and vendor of the VM.
You can also try something like this:

to see if Java can resolve the hostname to its IP (as this uses an internal class (couldn't get an example working without) this might only work on an oracle VM).
 
Bartender
Posts: 1899
17
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I sometimes get the same issue. On the Mac with MySQL I can get that error you mentioned or a "Connection lost". However, these issues also happen interactively with DB clients like Navicat so I don't think it's a Java or JDBC issue, but I haven't been able to figure this one out either.

-- mike
 
Kristina Hansen
Rancher
Posts: 144
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
well, then there seems to be another issue - checking with wireshark might help
 
Mick Dostie
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you guys for your help, I'm starting to think the host of my website and database might be the issue, since I can't reproduce the error running everything locally. One of the problems I am facing is that I cannot have Super privileges on the DB since I've done the website/DB on a shared hosting website (Complete beginner here and self-taught), and I can't change parameters like bind_address etc. I guess the best practice would be to have a VPS or at Cloud VPS. Perhaps the connection isn't established because of the bandwidth allocated to other sites or apps/noisy neighboors type of situation?

I think the next logical step would be to move the whole thing to a cloud VPS because I don't think my desktop app would be scalable with this setup, more users would most likely clog the drain further so to speak.

Might've bitten more than I can chew with front-end/back-end developpement of my desktop app and website by myself lol.

Thank you both for helping!
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic