数据库报错,如何解决?

来源:2-12 商品删除

StefanLee2015

2017-02-07 17:18

请问我在DBHelper类里面运行了main方法测试,但是报错如下,怎么解决呢?

com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception: 


** BEGIN NESTED EXCEPTION ** 


java.net.ConnectException

MESSAGE: Connection refused: connect


STACKTRACE:


java.net.ConnectException: Connection refused: connect

at java.net.PlainSocketImpl.socketConnect(Native Method)

at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351)

at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213)

at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200)

at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)

at java.net.Socket.connect(Socket.java:529)

at java.net.Socket.connect(Socket.java:478)

at java.net.Socket.<init>(Socket.java:375)

at java.net.Socket.<init>(Socket.java:218)

at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:173)

at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:267)

at com.mysql.jdbc.Connection.createNewIO(Connection.java:2739)

at com.mysql.jdbc.Connection.<init>(Connection.java:1553)

at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266)

at java.sql.DriverManager.getConnection(DriverManager.java:582)

at java.sql.DriverManager.getConnection(DriverManager.java:185)

at util.DBHelper.getConnection(DBHelper.java:34)

at util.DBHelper.main(DBHelper.java:44)



** END NESTED EXCEPTION **




Last packet sent to the server was 18 ms ago.

at com.mysql.jdbc.Connection.createNewIO(Connection.java:2814)

at com.mysql.jdbc.Connection.<init>(Connection.java:1553)

at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266)

at java.sql.DriverManager.getConnection(DriverManager.java:582)

at java.sql.DriverManager.getConnection(DriverManager.java:185)

at util.DBHelper.getConnection(DBHelper.java:34)

at util.DBHelper.main(DBHelper.java:44)


写回答 关注

1回答

  • 梅菜扣肉
    2017-02-08 20:12:03

    没有开启服务吧,资源管理器中---服务----服务--mysql,开启mysql服务

JAVA遇见HTML——Servlet篇

本门课程在JSP课程的基础上,深入介绍Servlet的基础知识

160615 学习 · 1029 问题

查看课程

相似问题