畅购商城学习日志9

发布时间 2023-09-18 17:04:56作者: 六月生

nested exception is org.apache.ibatis.exceptions.PersistenceException: \r\n### Error querying database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure\n\nThe last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.\r\n### The error may exist in com/changgou/goods/dao/CategoryMapper.java (best guess)\r\n### The error may involve com.changgou.goods.dao.CategoryMapper.select\r\n### The error occurred while executing a query\r\n### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure\n\nThe last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.--畅购商城学习日志

导航:

1.问题描述:

  • ​ nested exception is org.apache.ibatis.exceptions.PersistenceException: \r\n### Error querying database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure\n\nThe last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.\r\n### The error may exist in com/changgou/goods/dao/CategoryMapper.java (best guess)\r\n### The error may involve com.changgou.goods.dao.CategoryMapper.select\r\n### The error occurred while executing a query\r\n### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure\n\nThe last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.

2.思路经历:

  • 今天也是继续搞搞代码,突然Apifox说连接超时,冒了这一堆英文出来,大概是说连不上数据库啦,Navicat for MySQL提示说2003Unkown error。我寻思这代码我应该是没弄错的,而且显然是连接不上。所以得进入虚拟机看看啥毛病了,可是我发现我虚拟机的防火墙本来就是关着的,接着相互都ping通了,可真是奇了怪。

  • 那会不会是数据库没开?可是我再次启动MySQL服务,它说我已经开着。

  • 那会不会是端口被占用了?我Navicat那边端口用的是3306,是个默认端口,很有可能是idea帮我连接数据库的配置有问题了,我一看,哇端口是动态分配的

  • 所以,关闭idea,先连接Navicat,再开idea端口就能用了

3.产生原因:

  • ​ 这是一个持久化异常,可能是由于无法获取到JDBC连接导致的。同时,也提示了与MySQL通讯时出现了问题,可能是因为最后一个数据包从服务器发送成功的时间太久了,或者驱动程序没有从服务器接收到任何数据包。建议检查数据库连接配置是否正确,确保数据库服务正在运行,并检查网络连接是否正常。

4.解决方法:

  • 方法一

    • 将idea数据库配置的动态端口改为固定值3307或者别的数字
  • 方法二

    • 先启动Navicat,后启动idea,idea就会拿走一个还没占用的端口了