数据库连接:org.springframework.web.util.NestedServletException: Request processing failed;

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.jdbc.

CannotGetJdbcConnectionException: Failed to obtain JDBC Connection;

nested exception is java.sql.SQLException: Connections could not be acquired from the underlying database!

在这里插入图片描述

在学习SSM时,犯了一个比较低级的错误,虽然知道事数据库连接错误,但是不可否认,自己还是练的太少了,排除这个问题还是花了我不少的时间,小问题积累过多就是大问题,以此来警戒自己,每个问题都需要认真对待!

原因:
主要原因是版本兼容的问题,我XML中用的数据库连接版本是这样的:

<dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
      <version>5.1.32</version>
    </dependency>

然而我在properties中配置的是这样的:

jdbc.driver=com.mysql.cj.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai

解决
通过查阅资料,知道了XML中mysql的版本必须大于6.0以上才需要配置我写的properties中的形式,小于6.0以下的,只需要配置以下形式就可以:

jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/test

高版本则需要配置时区等等。
所以需要按照版本的不同来调整XML和properties,避免冲突!

同时谢谢博主大佬的启发:

https://www.cnblogs.com/dyf-stu/p/10053939.html

猜你喜欢

转载自blog.csdn.net/qq_42956993/article/details/108877956
今日推荐