前天调试12-5小结的那些模块代码,7个case全部运行通过,都没问题。昨天没开机,今天开机再运行一次,报 Cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure。中间没修改过任何代码,只在test.xml里添加了监听。做了以下排查:
- 注释掉监听语句。运行仍是报错。
- 重启sql服务。不行。
- 浏览器里直接敲入http://localhost:8888/v1/login,报: localhost拒绝了我们的连接请求。
- 更换端口号为8866,结果同上。
- 选取不调用数据库的方法运行,例如第9章中的方法,同样报拒绝请求。
没办法电脑重启,重启后localhost可以正常访问了,不调用数据库的方法都可正常运行。但是连接数据库的一些方法仍报以下错误:
浏览器报错:
There was an unexpected error (type=Internal Server Error, status=500).
nested exception is org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure Last packet sent to the server was 0 ms ago. ### The error may exist in file [D:\shane\muke\AutoInterface\Chapter11\target\classes\mapper\mysql.xml] ### The error may involve com.course.getUserCount ### The error occurred while executing a query ### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure Last packet sent to the server was 0 ms ago.
IDEA控制台报错:
ERROR org.apache.tomcat.jdbc.pool.ConnectionPool - Unable to create initial connections of pool.
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
麻烦老师看一下是什么问题,谢谢!