数据库连接出错---问题记录

本文探讨了在使用SpringJdbcTemplates时遇到的关于数据库连接的时区错误,涉及MySQL 8.0.18版本,重点在于如何解决服务器或JDBC驱动配置中的时区不识别问题,包括正确的数据库URL和驱动类设置。

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&amp;characterEncoding=UTF-8&amp;          zeroDateTimeBehavior=convertToNull&amp;useSSL=false&amp;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&amp;characterEncoding=UTF-8&amp;
          zeroDateTimeBehavior=convertToNull&amp;useSSL=false&amp;serverTimezone=UTC"></property>
        <property name="user" value="root"></property>
        <property name="password" value="123456"></property>
    </bean>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值