报错如下:
com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:
** BEGIN NESTED EXCEPTION **
java.net.SocketException
MESSAGE: java.net.ConnectException: Connection refused: connect
STACKTRACE:
java.net.SocketException: java.net.ConnectException: Connection refused: connect
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:156)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:284)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:2555)
at com.mysql.jdbc.Connection.<init>(Connection.java:1485)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at test.mysqlTest.getConnection(mysqlTest.java:24)
at test.mysqlTest.main(mysqlTest.java:43)
** END NESTED EXCEPTION **
and more
myeclipse连部上mysql,报错如上:
应该是没啥大问题的,但就是在我机器上连不上mysql.
困扰了几天,最后在mysql网站上看到这段:
"Connection reset by peer" means that a connection was made or partly made (somewhere) and then terminated on the remote end. Unfortunately, it doesn't tell you what was on the other end, or why it terminated the connection.
If the connection is being made through a proxying firewall (such as one that is doing NAT (network address translation)), what may be happening is that the firewall is receiving the connection request and accepting it on the extrnal side, while at the same time trying to open a connection on the internal side to the database. That's getting refused and then the firewall is tearing down the external connection. That's a long-winded way of saying that "Connection reset by peer" can be the same as "Connection refused" when there are connection-proxying network components in the transmission path.
You could be getting this because (1) the URL of the DB is wrong, because (2) the DB isn't set up to accept connections from the web host, or because (3) some intermediate networking component is misconfigured. (1) is your problem; (2) and (3) might be your problem or the web hosting's problem, depending on where the DB is located, what administrative privileges on the DB that you have, and how the networking is set up.
--转自