The Communications link failure due to underlying exception error in JDBC

Source: Internet
Author: User
Tags connection reset mysql database

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.