Reputation: 53
I'm making program in Java, which connects to MySQL database. As first class was class with single static method returning java.sql.Connection
. After it was debugged and connection was working I never touch it again. And few days ago I discovered my program was returning this error:
com.mysql.jdbc.CommunicationsException:
Communications link failure due to underlying exception
BEGIN NESTED EXCEPTION
com.mysql.jdbc.CommunicationsException
MESSAGE:
Communication link failure due to underlying exception:
BEGIN NESTED EXCEPTION
java.io.EOFException MESSAGE: Can not read response from server. Expected 4 bytes, read 0 before connection was unexpectedly lost.STACKTRACE:
...
Thing I can't understand is fact I didn't change user name and password on my localhost since I created my database. Only thing I changed are: add more tables and changed columns in tables, but that would not trigger this error. And thing I did with my project is I changed charset from UTF-8 to UTF-16, but I guess it hardly can affect my connection method.
If I change connector and put in classpath connector v. 5.1.22 it returns error:
Access denied for user "root@localhost" (using password: YES)
even I declared all privileges for user root.
Upvotes: 2
Views: 8465
Reputation: 53
I forgot tell I'm using Win 7 machine. Thank you for reply. I setup even more connections in my pool and it didn't work (I have about 10 connections to database, when application starts and pool accepts 15).
BUT!!
I didn't forget I changed my project's encoding from UTF-8 (I had since beginning) to Unicode (because I wanted use East European alphabet in JOptionPane.showMessageDialog();
windows, since its my native alphabet). Just for test I changed charset back to UTF-8 and my connection is working again. Honestly... I don't understand this.
Upvotes: 0
Reputation: 10866
I will recommend following:
- Firstly confirm if network is fine between two servers: a. ping from your server to your database server. b. use MTR unix tool to ensure connectivity between two servers.
- Are you using connection pool ? If yes, then try to restart the server. Probably few of the connections in your connection pool are in closed state.
Lets firstly resolve the first issue. Other issue Access denied for user "root@localhost" (using password: YES) is an independent issue which we can discuss later.
Upvotes: 1