1.在使用Spring JdbcTemplates模板连接数据库时出出现以下问题:
警告: com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@343cac5e – Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30). Last acquisition attempt exception:
java.sql.SQLException: The server time zone value ‘�й���ʱ��’ is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.
2.使用数据库8.0版本
则相关配置:
pom.xml导入 本地数据库的版本号
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.18</version>
</dependency>
bean.xml配置
<!--配置数据源 class="com.mchange.v2.c3p0.ComboPooledDataSource"-->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" >
<!--连接数据库的必备信息
jdbc:mysql;//localhost:3306/demo
jdbc:mysql://localhost:3306/demo?useUnicode=true&characterEncoding=UTF-8& zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=UTC
com.mysql.cj.jdbc.Driver
此时本地用的是8.0.18版本的数据库,则依赖包要8.0.18。此时driverClass,jdbc也要做修改
-->
<property name="driverClass" value="com.mysql.cj.jdbc.Driver"></property>
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/demo?useUnicode=true&characterEncoding=UTF-8&
zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=UTC"></property>
<property name="user" value="root"></property>
<property name="password" value="123456"></property>
</bean>
本文探讨了在使用SpringJdbcTemplates时遇到的关于数据库连接的时区错误,涉及MySQL 8.0.18版本,重点在于如何解决服务器或JDBC驱动配置中的时区不识别问题,包括正确的数据库URL和驱动类设置。
2394

被折叠的 条评论
为什么被折叠?



