I have a java application that runs on my work machine, but wont connect on the production server.
Heres the connection code:
String db = "jdbc:mysql://localhost:3306/"+database+
"?zeroDateTimeBehavior=convertToNull";
connect = DriverManager.getConnection(db, username, password);
Where the username, dbname and password are set correctly. When ran, I get:
com.mysql.jdbc.exceptions.jdbc4.CommunicationException: Communications link failure
I think it has to do with my iptables setup. When I telnet localhost 3306, My connection is refused; however, when I telnet the sever from another machine on port 3306 I can connect (the server accepts remote connections on the LAN). Is this normal behaviour?
I would have thought that localhost connections would work by default, but apparently not. The server is running debian btw. Any ideas whats going wrong here and how I can fix it?
Cheers.
Edit:
After temporarily resetting the iptables setup I'm starting to doubt that is where the problem is and it may be to do with the mysql config.
The bind address in my.cnf is set to the server IP - not 127.0.0.1. I can telnet from the local machine using the IP, but still can't connect with JDBC to it. From what I can tell mysql can only have one bind address. Perhaps theres something I need to tweak in the mysql setup...