本人是一个新手,随便写了一个jdbc小程序来连接mysql数据库,可是调试了很多次总是出现了一个很怪异的异常,异常信息如下:
Exception in thread "main" 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.(MysqlIO.java:276)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:2641)
at com.mysql.jdbc.Connection.(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)
at cn.itcast.jdbc.JdbcUtils.getConnection(JdbcUtils.java:33)
at cn.itcast.jdbc.Base.template(Base.java:33)
at cn.itcast.jdbc.Base.main(Base.java:23)
** END NESTED EXCEPTION **
Last packet sent to the server was 11 ms ago.
at com.mysql.jdbc.Connection.createNewIO(Connection.java:2707)
at com.mysql.jdbc.Connection.(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)
at cn.itcast.jdbc.JdbcUtils.getConnection(JdbcUtils.java:33)
at cn.itcast.jdbc.Base.template(Base.java:33)
at cn.itcast.jdbc.Base.main(Base.java:23)
不知道这是什么原因所造成的,在google上也搜了很多,可是没有找到恰当的解决方案,请各位牛人帮忙看一下。我通过Mysql Query可以连接到mysql的数据库。应该是在建立连接的时候出现了问题。
等待。。。