项目场景:

在spring整合mybatis中,使用druid时,出现疯狂爆红,以此作记录:

问题描述:

九月 28, 2020 6:35:08 下午 com.alibaba.druid.support.logging.JakartaCommonsLoggingImpl error
严重: create connection SQLException, url: jdbc:mysql://localhost:3306/node, errorCode 0, state 01S00
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.
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129)
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)


原因分析:


mysql驱动配置出错:我的数据库是mysql 8.0.18版本


解决方案:

 <!--声明数据源DataSource,作用是连接数据库-->
    <bean id="myDataSource" class="com.alibaba.druid.pool.DruidDataSource"
          init-method="init" destroy-method="close">
        <!--set注入给DruidDataSource提供连接数据库信息-->
        <property name="driverClassName" value="com.mysql.cj.jdbc.Driver"/>
        <property name="url" value="jdbc:mysql://localhost:3306/自己的数据库名?serverTimezone=UTC&amp;
                  useUnicode=true&amp;characterEncoding=UTF-8&amp;useSSL=false" /><!--${jdbc_url}-->
        <property name="username" value="用户名" /><!--${jdbc_user}-->
        <property name="password" value="自己的密码"/><!--${jdbc_password}-->
        <property name="maxActive" value="20" />
    </bean>
重点:(主要解决出错的位置)
  <property name="driverClassName" value="com.mysql.cj.jdbc.Driver"/>
        <property name="url" value="jdbc:mysql://localhost:3306/自己的数据库名?serverTimezone=UTC&amp;
                  useUnicode=true&amp;characterEncoding=UTF-8&amp;useSSL=false" /><!--${jdbc_url}-->
Logo

更多推荐