怎么办这是Apifox里执行http://localhost:9002/goods/getByUserName?name=“张三“为什么我改了还是500?

{ "timestamp": "2025-10-02T11:27:53.384+0000", "status": 500, "error": "Internal Server Error", "message": "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.jdbc.exceptions.jdbc4.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 file [D:\SUM\代码\demo251001\target\classes\mapper\UserMapper.xml]\r\n### The error may involve com.daqin.demo251001.mapper.UserMapper.getByUserName\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.jdbc.exceptions.jdbc4.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.", "path": "/goods/getByUserName" }怎么办这是Apifox里执行http://localhost:9002/goods/getByUserName?

name="张三"为什么我改了还是500?

根据错误信息分析,这是一个数据库连接失败的问题,而不是之前的MyBatis映射问题。主要错误是:

```

Failed to obtain JDBC Connection; nested exception is com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

```

问题分析

这是一个典型的数据库连接通信失败错误,常见原因包括:

解决方案

  1. **检查数据库服务状态**
  • 确认MySQL数据库服务是否正在运行

  • 检查数据库是否可以通过其他工具(如Navicat、MySQL Workbench)正常连接

  1. **检查application.yml/application.properties配置**

```yaml

spring:

datasource:

url: jdbc:mysql://localhost:3306/your_database_name

username: your_username

password: your_password

driver-class-name: com.mysql.cj.jdbc.Driver

```

  1. **检查数据库连接参数**
  • 确认数据库地址(`localhost`)、端口(`3306`)是否正确

  • 确认数据库名称是否存在

  • 确认用户名和密码是否正确

  • 检查是否需要添加时区参数: `?serverTimezone=UTC`

  1. **检查网络连接**
  • 确认应用程序能够访问数据库服务器

  • 检查防火墙是否阻止了数据库端口

  1. **检查MySQL驱动依赖**

```xml

<dependency>

<groupId>mysql</groupId>

<artifactId>mysql-connector-java</artifactId>

</dependency>

```

  1. **增加连接池配置**

```yaml

spring:

datasource:

hikari:

connection-timeout: 20000

maximum-pool-size: 10

minimum-idle: 5

```

建议先检查数据库服务和连接配置是否正确。

相关推荐
木木子99993 小时前
业务架构、应用架构、数据架构、技术架构
java·开发语言·架构
RAN_PAND3 小时前
计算机组成原理实验
网络·计算机组成原理
守城小轩4 小时前
轻量级HTTP&Socks代理GOST: Win编译安装
网络·网络协议·代理网络
七七七七074 小时前
【计算机网络】深入理解ARP协议:工作原理、报文格式与安全防护
linux·服务器·网络·计算机网络·安全
守城小轩4 小时前
轻量级HTTP&Socks代理GOST: Linux编译安装
运维·网络·网络协议
qq_5470261795 小时前
Flowable 工作流引擎
java·服务器·前端
奋斗的蛋黄6 小时前
网络卡顿运维排查方案:从客户端到服务器的全链路处理
运维·服务器·网络
鼓掌MVP6 小时前
Java框架的发展历程体现了软件工程思想的持续进化
java·spring·架构
编程爱好者熊浪6 小时前
两次连接池泄露的BUG
java·数据库
lllsure6 小时前
【Spring Cloud】Spring Cloud Config
java·spring·spring cloud