Problem description:When you connect to the Mysql database using JDBC, the "Connection reset" error occurs and the following exception is thrown:
Connection couldn't be established to jdbc: mysql ://***/***? User = *** & password = ********
Com. mysql. jdbc. CommunicationsException: Communications link failure due to underlying exception:
** Begin nested exception **
Com. mysql. jdbc. CommunicationsException
MESSAGE: Communications link failure due to underlying exception: ** begin nested exception **
Java.net. SocketException
MESSAGE: Connection reset
STACKTRACE: java.net. SocketException: Connection reset
At java.net. SocketInputStream. read (Unknown Source)
At com. mysql. jdbc. util. ReadAheadInputStream. fill (ReadAheadInputStream. java: 113)
At com. mysql. jdbc. util. ReadAheadInputStream. readFromUnderlyingStreamIfNecessary (ReadAheadInputStream. java: 160)
At com. mysql. jdbc. util. ReadAheadInputStream. read (ReadAheadInputStream. java: 188)
At com. mysql. jdbc. MysqlIO. readFully (MysqlIO. java: 1910)
At com. mysql. jdbc. MysqlIO. reuseAndReadPacket (MysqlIO. java: 2304)
At com. mysql. jdbc. MysqlIO. checkErrorPacket (MysqlIO. java: 2803)
At com. mysql. jdbc. MysqlIO. sendCommand (MysqlIO. java: 1573)
At com. mysql. jdbc. MysqlIO. sqlQueryDirect (MysqlIO. java: 1665)
At com.mysql.jdbc.Connection.exe cSQL (Connection. java: 3170)
At com. mysql. jdbc. Connection. configureClientCharacterSet (Connection. java: 2436)
At com. mysql. jdbc. Connection. initializePropsFromServer (Connection. java: 3913)
At com. mysql. jdbc. Connection. createNewIO (Connection. java: 2683)
At com. mysql. jdbc. Connection. <init> (Connection. java: 1531)
At com. mysql. jdbc. NonRegisteringDriver. connect (NonRegisteringDriver. java: 266)
At java. SQL. DriverManager. getConnection (Unknown Source)
At java. SQL. DriverManager. getConnection (Unknown Source)
...... ** End nested exception **
Last packet sent to the server was 203 MS ago.
STACKTRACE:
Com. mysql. jdbc. CommunicationsException: Communications link failure due to underlying exception:
** Begin nested exception ** java.net. SocketException
MESSAGE: Connection reset
STACKTRACE:
Java.net. SocketException: Connection reset
At java.net. SocketInputStream. read (Unknown Source)
At com. mysql. jdbc. util. ReadAheadInputStream. fill (ReadAheadInputStream. java: 113)
At com. mysql. jdbc. util. ReadAheadInputStream. readFromUnderlyingStreamIfNecessary (ReadAheadInputStream. java: 160)
At com. mysql. jdbc. util. ReadAheadInputStream. read (ReadAheadInputStream. java: 188)
At com. mysql. jdbc. MysqlIO. readFully (MysqlIO. java: 1910)
At com. mysql. jdbc. MysqlIO. reuseAndReadPacket (MysqlIO. java: 2304)
At com. mysql. jdbc. MysqlIO. checkErrorPacket (MysqlIO. java: 2803)
At com. mysql. jdbc. MysqlIO. sendCommand (MysqlIO. java: 1573)
At com. mysql. jdbc. MysqlIO. sqlQueryDirect (MysqlIO. java: 1665)
At com.mysql.jdbc.Connection.exe cSQL (Connection. java: 3170)
At com. mysql. jdbc. Connection. configureClientCharacterSet (Connection. java: 2436)
At com. mysql. jdbc. Connection. initializePropsFromServer (Connection. java: 3913)
At com. mysql. jdbc. Connection. createNewIO (Connection. java: 2683)
At com. mysql. jdbc. Connection. <init> (Connection. java: 1531)
At com. mysql. jdbc. NonRegisteringDriver. connect (NonRegisteringDriver. java: 266)
At java. SQL. DriverManager. getConnection (Unknown Source)
At java. SQL. DriverManager. getConnection (Unknown Source)
......
** End nested exception **
Problem analysis:This error occurs because the Java program is not connected to Mysql and thus cannot perform any database-related operations. The essence of this error is a network problem.
Solution:First, you need to troubleshoot the following situations:
(1) whether the MySql server supports TCP/IP connection;
(2) whether the firewall is enabled on the server and the client running Java programs;
(3) whether the JDBC driver is correct or not;
(4) is IPv6 enabled? If you are using IPv6, replace it with IPv4 and try again;
If the above exception occurs after all the above conditions are ruled out, it is likely that the network on your computer is faulty, you can try to run the Java program containing JDBC on the Internet in another place or run it again at another time.